Mailer Behaviour... Testing with Rails Console

Ok, even though I haven’t gotten the Mailer behaviour to work on my site
yet. I have some notes here that might help others with testing their
ActionMailer configuration.

My environment:
eApps (CentOS)

Here’s what I’ve done so far…

TESTING with Telnet

Tested my SMTP server using telnet. Discovered that there was something
wrong with the server config. Had my ISP tech support look at it and it
was fixed. Tested again using Telnet as show below

telnet 25
MAIL FROM: [email protected]
RCPT TO: [email protected]
Subject: Test Message
From: [email protected]
To: [email protected]

This is a test message using Telnet against the SMTP server

After confirming that my SMTP server was working then I could be sure
that the problem was somewhere in my environment.rb ActionMailer
configuration. Here my original configuration:


Configure ActionMailer

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.server_settings = {
:address => “”,
:port => 25,
:domain => “xxxxxxxxxxxxxxx”,
:user_name => “xxxxxxxx”,
:password => “xxxxxxxxxx”,
:authentication => :login

When attempting to send emails using the Mailer Behaviour I would not
get an error but the email would not be delivered. Also, a clue that
something was not working correctly is that the redirect was not working
(instead of going to /contact/thank-you it was just going back to

In the in the maillog file all I see a line like (note that I’m not sure
this is line is directly related to the email being set):

Feb 4 00:57:16 integrallis sendmail[18081]: l145vG69018081: from=root,
size=0, class=0, nrcpts=0,
msgid=[email protected],


But, no email was ever delivered. Also I check the mail queue using the
mailq command, so this tells me the messages are not even being placed
in the queue:

/var/spool/mqueue is empty
Total requests: 0

TESTING using Rails Console

then it was time to move into testing ActionMailer using the Rails

So I log into my server and su as the user that the webserver runs

Then I cd to the radiant directory and type:

script/console production

You should see something like this:

Loading production environment.
`const_missing’:NameError: uninitialized constant

(I’m not quite sure what this const_missing is all about but I just
ignored it for the time being)

Now we create a ActionMailer instance and add a method to send a simple
test email:

class MyMailer < ActionMailer::Base
def test_email
@recipients = “[email protected]
@from = “[email protected]
@subject = “test from the Rails Console”
@body = “This is a test email”

After the last ‘end’ you should see :
=> nil

Then to send the email type:


In my case I got the following error:

→ “220 ESMTP Sendmail 8.13.1/8.13.1;
Sat, 3 Feb 2007 20:42:09 -0500\r\n”
← “EHLO\r\n”
→ “ Hello [], pleased to meet you\r\n”
→ “250-PIPELINING\r\n”
→ “250-8BITMIME\r\n”
→ “250-SIZE\r\n”
→ “250-DSN\r\n”
→ “250-ETRN\r\n”
→ “250-DELIVERBY\r\n”
→ “250 HELP\r\n”
← “STARTTLS\r\n”
→ “454 4.3.3 TLS not available after start\r\n”
Net::SMTPServerBusy: 454 4.3.3 TLS not available after start

    from /usr/lib/ruby/1.8/net/smtp.rb:680:in `check_response'
    from /usr/lib/ruby/1.8/net/smtp.rb:653:in `getok'

starttls' from ./script/../config/../config/../vendor/plugins/action_mailer_tls/lib/smtp_tls.rb:19:in do_start’
from /usr/lib/ruby/1.8/net/smtp.rb:378:in start' from /usr/lib/ruby/1.8/net/smtp.rb:316:in start’
perform_delivery_smtp' from ./script/../config/../config/../vendor/rails/actionmailer/lib/action_mailer/base.rb:397:in deliver!’
from (irb):9

This really confused me since I was able to send emails using telnet
without using any kind of authentication (other than the fact that I was
telneting locally and logged in as the webserver user)

I don’t know that much about SMTP but the error above is related to
Secure SMTP over TLS.


So I decided to switch the delivery method in the ActionMailer
configuration from smtp to sendmail and removing any authentication
related information. So my ActionMailer configuration was reduced to:

ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true

After these changes I tried sending a test email again using the Rails
console and voila it worked! In the Rails console I know see:

#<TMail::Mail port=#TMail::StringPort:id=0x..fdbd11716

In the maillog now I see this:

Feb 3 23:35:39 integrallis sendmail[11957]: l144Zctf011957: Milter add:
header: Received-SPF: pass ( domain of
[email protected] designates as permitted
sender); client-ip=;;
[email protected];
x-software=spfmilter 0.97 spfmilter with
Feb 3 23:35:39 integrallis sendmail[11956]: l144ZcZs011956:
[email protected], ctladdr=root (0/0), delay=00:00:01,
xdelay=00:00:01, mailer=relay, pri=30162, relay=[] [],
dsn=2.0.0, stat=Sent (l144Zctf011957 Message accepted for delivery)
Feb 3 23:35:40 integrallis sendmail[11963]: l144Zctf011957:
to=[email protected],
ctladdr=[email protected] (0/0), delay=00:00:02,
xdelay=00:00:01, mailer=esmtp, pri=120418,
[], dsn=2.0.0, stat=Sent (Ok: queued as 0BDC34A43D5)

So, naive me I was all happy thinking well, if ActionMailer now works
from the Rails Console the Mailer behaviour should for sure work. Well,
not so fast. My emails are still not being delivered!!! Argh

I have checked and double check my configuration. If you can see
anything wrong with it I would appreciate a quick note.

In my contacts page I have:

config part:

subject: Contact Request
from: [email protected]
redirect_to: /en/contact/thank-you
- [email protected]

body part:

Contact us

Your name:

Your email:

Your comments:

email part:

Name: <r:mailer:get name=“name” />
Email: <r:mailer:get name=“email” />
Comments: <r:mailer:get name=“comments” />

Here what I see on my production.log (regardless of how ActionMailer was

Processing SiteController#show_page (for at 2007-01-28
17:56:17) [POST]
Parameters: {“mailer”=>{“name”=>“test”, “comments”=>“test”,
“subject”=>“Contact Request!”, “email”=>“[email protected]”},
“action”=>“show_page”, “url”=>[“en”, “contact”],
“mailer_name”=>“contact”, “controller”=>“site”}
Completed in 0.04633 (21 reqs/sec) | DB: 0.00970 (20%) | 200 OK

I’ve search all my other logs but don’t see any errors.