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

**URL:** <https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162>\
**Category:** Ruby\
**Created:** [March 9, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162 "2006-03-09T19:40:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/1 "2006-03-09T19:40:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 7:46pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/2 "2006-03-09T19:46:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/3 "2006-03-09T20:34:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 9:36pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/4 "2006-03-09T21:36:33Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/5 "2006-03-09T21:45:38Z")

</div>

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.  
…

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 9:51pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/6 "2006-03-09T21:51:44Z")

</div>

another follow up… the code I posted does not work from the same usr  
same  
machine where login would not be necessary.

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 9, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/7 "2006-03-09T23:54:00Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 10, 2006, 5:25pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/8 "2006-03-10T17:25:37Z")

</div>

Logan C. wrote:

> 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](http://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=[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
[relay=mailfoundry-1.iphouse.net](http://relay=mailfoundry-1.iphouse.net)[216.250.188.210],  
delay=4, status=deferred (host  
[mailfoundry-1.iphouse.net](http://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  
removed\_email\_address@domain.invalid is the valid email address I used in the code.

???  
john

---

<div class="post-metadata">

**Author:** ![John\_NSAlegre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@John\_NSAlegre](https://www.ruby-forum.com/u/John_NSAlegre)\
**Post date:** [March 10, 2006, 10:26pm UTC](https://www.ruby-forum.com/t/cant-get-net-smtp-to-send-outside-of-lan/79162/9 "2006-03-10T22:26:42Z")

</div>

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
