Can't get net/smtp to send outside of LAN?

Discussion in 'Ruby' started by John N. Alegre, Mar 9, 2006.

  1. I am trying to use net/smtp to send a mail message. What I am finding is
    that I can send a email message on the LAN but it never gets out to the
    world. What am I missing?

    Here is my test code:
    ####################################################################
    require('net/smtp')

    class Email
    def Email.send(date, body, server = 'localhost', port = 25)
    Net::SMTP.start(server, port) { |mailer|
    text =
    "From: info\n" <<
    "To: usr@domain\n" <<
    "Date: #{date}\n" <<
    "Subject: New entry in Database\n" <<
    "Importance: High\n" <<
    "MIME-Version: 1.0\n" <<
    "Sender: #{self.class.name}\n" <<
    "\n\n\n" <<
    body

    mailer.send_message(text, "info", "usr@domain")
    }
    end

    end

    Email.send("#{Time.now}", "New entry in database at #{ Time.now}\n")
    puts "end of code"
    ####################################################################
    on the LAN SMTP server with 'localhost' and usr@domain being a user on the
    same machine WORKS OK ... with 'localhost' replaced with 'machine' where
    machine is the machine on the LAN that sends SMTP mail and usr@domain is a
    user on that same machine and the code is run anywhere on the LAN it WORKS
    OK to a user on 'machine' ...

    HOWEVER ...

    if usr@domain is outside the LAN the mail never gets sent either if the code
    is run on 'localhost' or on a machine on the LAN with 'machine' replaced by
    the IP of the SMTP server. I know 'machine' will serve as a SMTP host for
    mailers such as evolution or Mac OX X mailer because I use it for that all
    the time.

    What am I missing.

    I know I could go to a better Ruby package such as TMail or RubyMail or
    bring out the cannons and use ActionMailer but if I don't understand what
    is happening at this basic level that might not help either.

    All comments welcome
    john
     
    John N. Alegre, Mar 9, 2006
    #1
    1. Advertising

  2. John N. Alegre

    gregarican Guest

    John N. Alegre wrote:

    > I am trying to use net/smtp to send a mail message. What I am finding is
    > that I can send a email message on the LAN but it never gets out to the
    > world. What am I missing?


    I think you are forgetting login credentials such as
    ....acct="username", passwd="password", authtype=:login as part of the
    instance's construction.
     
    gregarican, Mar 9, 2006
    #2
    1. Advertising

  3. gregarican wrote:

    > I think you are forgetting login credentials such as
    > ...acct="username", passwd="password", authtype=:login as part of the
    > instance's construction.
    >

    but is this necessary???

    When I set the SMTP server as host on mailers such as evolution or the Mac
    OX X mailer I use no user / pass authorization. I just pass the mail to
    that machine using SMTP. Why would this be different from Ruby code?
     
    John N. Alegre, Mar 9, 2006
    #3
  4. John N. Alegre

    gregarican Guest

    John N. Alegre wrote:

    > When I set the SMTP server as host on mailers such as evolution or the Mac
    > OX X mailer I use no user / pass authorization. I just pass the mail to
    > that machine using SMTP. Why would this be different from Ruby code?


    Are you 100% sure there is no username/password combo stored in a
    keychain or any other place on your Mac? If there is that's why the Mac
    is automatically referencing this. Much like how my Outlook/Exchange
    environment stores my information. But if I want to access raw SMTP
    using Ruby I need to manually authenticate. Just a wild guess...
     
    gregarican, Mar 9, 2006
    #4
  5. gregarican wrote:

    > Are you 100% sure there is no username/password combo stored in a
    > keychain or any other place on your Mac?


    Yes there is nothing set in mailers from three different platforms. 2 other
    linux boxes and one Mac (evolution or Mac Mailer) there is an "Trusted
    Net:" entry in the firewall config but this would be the same for the code
    as for the mailers.
    ...
     
    John N. Alegre, Mar 9, 2006
    #5
  6. another follow up.... the code I posted does not work from the same usr same
    machine where login would not be necessary.

    gregarican wrote:

    > John N. Alegre wrote:
    >
    >> When I set the SMTP server as host on mailers such as evolution or the
    >> Mac
    >> OX X mailer I use no user / pass authorization. I just pass the mail to
    >> that machine using SMTP. Why would this be different from Ruby code?

    >
    > Are you 100% sure there is no username/password combo stored in a
    > keychain or any other place on your Mac? If there is that's why the Mac
    > is automatically referencing this. Much like how my Outlook/Exchange
    > environment stores my information. But if I want to access raw SMTP
    > using Ruby I need to manually authenticate. Just a wild guess...
     
    John N. Alegre, Mar 9, 2006
    #6
  7. --Apple-Mail-32-428678994
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain;
    charset=US-ASCII;
    delsp=yes;
    format=flowed


    On Mar 9, 2006, at 3:33 PM, gregarican wrote:

    >
    > Are you 100% sure there is no username/password combo stored in a
    > keychain or any other place on your Mac? If there is that's why the
    > Mac
    > is automatically referencing this. Much like how my Outlook/Exchange
    > environment stores my information. But if I want to access raw SMTP
    > using Ruby I need to manually authenticate. Just a wild guess...


    Are you sure you're not confusing SMTP with POP? You as a general
    rule _don't_ have to authenticate with SMTP, although many SMTP
    servers do have some form of authentication (e.g. require someone to
    log in with POP first, etc.)


    --Apple-Mail-32-428678994--
     
    Logan Capaldo, Mar 9, 2006
    #7
  8. Re: Can't get net/smtp to send outside of LAN

    Logan Capaldo wrote:

    >
    > On Mar 9, 2006, at 3:33 PM, gregarican wrote:
    >
    >>
    >> Are you 100% sure there is no username/password combo stored in a
    >> keychain or any other place on your Mac? If there is that's why the
    >> Mac
    >> is automatically referencing this. Much like how my Outlook/Exchange
    >> environment stores my information. But if I want to access raw SMTP
    >> using Ruby I need to manually authenticate. Just a wild guess...

    >
    > Are you sure you're not confusing SMTP with POP? You as a general
    > rule don't have to authenticate with SMTP, although many SMTP
    > servers do have some form of authentication (e.g.  require someone to
    > log in with POP first, etc.)


    Yes this is definately the case.  I obtained a Perl script that sends email
    to the SMTP server I am trying to work with the Ruby code on and it works
    fine after I change what I got to the hostname of the SMTP server.  Greg is
    confusing POP with SMTP.

    But back to the code.

    Again I post my Ruby test code ...require('net/smtp')

    ########################################################
    class Email
      def Email.send(date, body, server = 'localhost', port = 25)
        Net::SMTP.start(server, port) { |mailer|
          text = 
          "From: info\n" << 
          "To: usr@domain\n"       <<
          "Date: #{date}\n"          <<
          "Subject: New entry in Database\n"        <<
          "Importance: High\n"           <<
          "MIME-Version: 1.0\n"          <<
          "Sender: #{self.class.name}\n" <<
          "\n\n\n"                       <<
          body

          mailer.send_message(text, "info", "usr@domain")
          }
      end

    Email.send("#{Time.now}", "New entry in database at #{ Time.now}\n")
    puts "end of code"
    ########################################################
    This works to send mail to a user on the SMTP server machine.  This machine
    has 30 users and I can send mail to any of those users, routed correctly.
    Any email address outside the LAN disappers.

    Here is the entry in the mail log:

    endMar 10 09:21:31 libros postfix/smtp[24290]: 0F60E13FB0: host
    mailfoundry-2.iphouse.net[216.250.188.211] said: 450 Domain in Reverse-Path
    resolves to an invalid IP address (in reply to RCPT TO command)
    Mar 10 09:21:33 libros postfix/smtp[24290]: 0F60E13FB0:
    to=<>, relay=mailfoundry-1.iphouse.net[216.250.188.210],
    delay=4, status=deferred (host mailfoundry-1.iphouse.net[216.250.188.210]
    said: 450 Domain in Reverse-Path resolves to an invalid IP address (in
    reply to RCPT TO command))

    so the domain, even though it is correct is somehow being munged by Ruby to
    something that the downstream realy does NOT understand. (here
    is the valid email address I used in the code.

    ?????????????????????????
    john
     
    John N. Alegre, Mar 10, 2006
    #8
  9. [SOLVED] Re: Can't get net/smtp to send outside of LAN?

    For anyone who has been following this thread I have solved the problem.
    Well I guess a better term is there never was a problem. Two months ago I
    changed IPs and got a new block of static IPs. The entry for reverse DNS
    lookup on the mail software they use was set to require reverse DNS for
    email. Things like evolution or the Macintosh OS X mailers do reverse DNS
    so those things worked fine. The raw code however did not handle revers
    DNS so the mail send failed. Once they changed the entry the code shown
    below will send mail out just fine.

    Hope this helps someone else.

    Peace
    john

    John N. Alegre wrote:

    > I am trying to use net/smtp to send a mail message. What I am finding is
    > that I can send a email message on the LAN but it never gets out to the
    > world. What am I missing?
    >
    > Here is my test code:
    > ####################################################################
    > require('net/smtp')
    >
    > class Email
    > def Email.send(date, body, server = 'localhost', port = 25)
    > Net::SMTP.start(server, port) { |mailer|
    > text =
    > "From: info\n" <<
    > "To: usr@domain\n" <<
    > "Date: #{date}\n" <<
    > "Subject: New entry in Database\n" <<
    > "Importance: High\n" <<
    > "MIME-Version: 1.0\n" <<
    > "Sender: #{self.class.name}\n" <<
    > "\n\n\n" <<
    > body
    >
    > mailer.send_message(text, "info", "usr@domain")
    > }
    > end
    >
    > end
    >
    > Email.send("#{Time.now}", "New entry in database at #{ Time.now}\n")
    > puts "end of code"
    > ####################################################################
    > on the LAN SMTP server with 'localhost' and usr@domain being a user on the
    > same machine WORKS OK ... with 'localhost' replaced with 'machine' where
    > machine is the machine on the LAN that sends SMTP mail and usr@domain is a
    > user on that same machine and the code is run anywhere on the LAN it WORKS
    > OK to a user on 'machine' ...
    >
    > HOWEVER ...
    >
    > if usr@domain is outside the LAN the mail never gets sent either if the
    > code is run on 'localhost' or on a machine on the LAN with 'machine'
    > replaced by
    > the IP of the SMTP server. I know 'machine' will serve as a SMTP host for
    > mailers such as evolution or Mac OX X mailer because I use it for that all
    > the time.
    >
    > What am I missing.
    >
    > I know I could go to a better Ruby package such as TMail or RubyMail or
    > bring out the cannons and use ActionMailer but if I don't understand what
    > is happening at this basic level that might not help either.
    >
    > All comments welcome
    > john
     
    John N. Alegre, Mar 10, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. michi
    Replies:
    1
    Views:
    3,596
    Hermit Dave
    Jan 29, 2004
  2. Curt_C [MVP]
    Replies:
    3
    Views:
    552
    Charlie@CBFC
    Feb 2, 2004
  3. darrel
    Replies:
    5
    Views:
    360
    Plamen Ratchev
    Dec 29, 2006
  4. =?Utf-8?B?Y2hpZWtv?=

    Can't send email outside of the network

    =?Utf-8?B?Y2hpZWtv?=, Mar 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    372
    =?Utf-8?B?Y2hpZWtv?=
    Mar 9, 2007
  5. Krzysztof Poc

    outside type, outside function

    Krzysztof Poc, Feb 3, 2012, in forum: C++
    Replies:
    1
    Views:
    290
    Victor Bazarov
    Feb 7, 2012
Loading...

Share This Page