# ActionMailer cannot use SMTP for email delivery

**URL:** <https://www.ruby-forum.com/t/actionmailer-cannot-use-smtp-for-email-delivery/65162>\
**Category:** Rails\
**Created:** [August 16, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/actionmailer-cannot-use-smtp-for-email-delivery/65162 "2006-08-16T16:32:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Vandenberk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@Peter\_Vandenberk](https://www.ruby-forum.com/u/Peter_Vandenberk)\
**Post date:** [August 16, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/actionmailer-cannot-use-smtp-for-email-delivery/65162/1 "2006-08-16T16:32:33Z")

</div>

RoR aficionados,

I’ve configured ActionMailer for SMTP delivery of emails, and have  
configured “config/environment.rb” accordingly, including the address of  
our (external, but fully operational - checked and double-checked 🙂  
SMTP server.

Sending out emails from my Windows development laptop works without a  
hitch, but on a Linux staging server using the exact same source code  
with the exact same config files it doesn’t work; the symptoms are as  
follows…

If I put the name of the SMTP server in “config/environment.rb” I get  
the following SocketError on the Linux box:

```
getaddrinfo: Temporary failure in name resolution
/usr/lib/ruby/1.8/net/protocol.rb:206:in `initialize'
...

```

If I put the SMTP’s IP address in “config/environment.rb” instead of  
it’s name, it doesn’t work either, but this time with a Errno::EACCES  
instead of the SocketError (again on the Linux box):

```
 Permission denied - socket(2)
 /usr/lib/ruby/1.8/net/protocol.rb:206:in `initialize'
 ...

```

Which is very strange, because if I run the following snippets on the  
same Linux box, I don’t get any errors whatsoever:

```
  ruby -rsocket -e 'p Socket.getaddrinfo("NAME_OF_SMTP", "smtp")'
  ruby -rsocket -e 'p Socket.getaddrinfo("IP_OF_SMTP", "smtp")'

```

So it doesn’t appear to be a firewall, proxy or other configuration  
issue on the box that’s causing the problem.

Also, a small Ruby program that invokes “TCPsocket.new” on port 25 of  
the SMTP server works correctly on the Linux box, and another small Ruby  
program that invokes “Net::SMTP.start” directly (ie. outside of Rails)  
to deliver an email via the same SMTP server correctly delivers the  
email from that Linux box… it’s just Rails that seems to be unable to  
deliver the email via SMTP.

So it doesn’t appear to be a Rails configuration issue (as the config  
works on my Windows laptop) but at the same time it also doesn’t appear  
to be a configuration issue of the Linux box (as Ruby outside of Rails  
can correctly deliver email via SMTP) ???

I’ve gone through the stacktrace (attached below) with a fine comb, and  
“TCPsocket.new” and “Net::SMTP.start” seem to be the most relevant  
things to check (which I’ve successfully done, as mentioned above).

An earlier post on this mailing list seems to describe the same (or - at  
least - sufficiently similar) issue:

[http://lists.rubyonrails.org/pipermail/rails/2006-January/013967.html](http://lists.rubyonrails.org/pipermail/rails/2006-January/013967.html)

but it appears no-one ever posted a follow-up.

Many, many thanks in advance for any help (fix, further pointers) you  
can offer.

Peter Vandenberk

PS - full Rails stacktrace (Rails 1.1.6, ActionMailer 1.2.5)

/usr/lib/ruby/1.8/net/protocol.rb:206:in `initialize' /usr/lib/ruby/1.8/net/protocol.rb:206:in `old\_open’  
/usr/lib/ruby/1.8/timeout.rb:56:in `timeout' /usr/lib/ruby/1.8/timeout.rb:76:in `timeout’  
/usr/lib/ruby/1.8/net/protocol.rb:206:in `old_open' /usr/lib/ruby/1.8/net/smtp.rb:393:in `do\_start’  
/usr/lib/ruby/1.8/net/smtp.rb:378:in `start' /usr/lib/ruby/1.8/net/smtp.rb:316:in `start’  
/usr/lib/ruby/gems/1.8/gems/actionmailer-1.2.5/lib/action\_mailer/base.rb:511:in  
`perform_delivery_smtp' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.2.5/lib/action_mailer/base.rb:397:in `deliver!’  
/usr/lib/ruby/gems/1.8/gems/actionmailer-1.2.5/lib/action\_mailer/base.rb:322:in  
`deliver’

---

<div class="post-metadata">

**Author:** ![Peter\_Vandenberk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@Peter\_Vandenberk](https://www.ruby-forum.com/u/Peter_Vandenberk)\
**Post date:** [August 18, 2006, 12:02pm UTC](https://www.ruby-forum.com/t/actionmailer-cannot-use-smtp-for-email-delivery/65162/2 "2006-08-18T12:02:02Z")

</div>

For future reference, in case other people run into the same issue: as  
it turns out, the SMTP problem I reported earlier was caused by the fact  
that I was running my Rails application via Apache/CGI on a SELinux  
box… the default SELinux policy disallows HTTPD scripts/modules from  
connecting to the network, hence the error messages I was getting: SMTP  
from WebRICK, “script/runner” etc. was working, but was failing from  
Apache.

Changing the “Allow HTTP scripts and modules to connect to the network”  
setting in the SELinux policy solved the SMTP problem I was experiencing  
in my Rails app.

Doing so probably opened up a whole can of security issues, but at least  
email is now working! 🙂 Luckily the CGI thing is just a temporary  
setup… phew!

FYI,

Peter
