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 127.0.0.1 25
HELO mydomain.com
MAIL FROM: [email protected]
RCPT TO: [email protected]
DATA
Subject: Test Message
From: [email protected]
To: [email protected]
This is a test message using Telnet against the SMTP server
.
QUIT
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:
environment.rb
Configure ActionMailer
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.server_settings = {
:address => “127.0.0.1”,
: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
/contact)
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],
relay=root@localhost
CHECK THE MAILQ
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:
mailq
/var/spool/mqueue is empty
Total requests: 0
TESTING using Rails Console
then it was time to move into testing ActionMailer using the Rails
Console:
So I log into my server and su as the user that the webserver runs
under.
Then I cd to the radiant directory and type:
script/console production
You should see something like this:
Loading production environment.
./script/…/config/…/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:100:in
`const_missing’:NameError: uninitialized constant
ActionController::TestProcess
(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”
end
end
After the last ‘end’ you should see :
=> nil
Then to send the email type:
MyMailer::deliver_test_email
In my case I got the following error:
→ “220 integrallis.virtual.vps-host.net ESMTP Sendmail 8.13.1/8.13.1;
Sat, 3 Feb 2007 20:42:09 -0500\r\n”
← “EHLO integrallis.com\r\n”
→ “250-integrallis.virtual.vps-host.net Hello
integrallis.virtual.vps-host.net [127.0.0.1], pleased to meet you\r\n”
→ “250-ENHANCEDSTATUSCODES\r\n”
→ “250-PIPELINING\r\n”
→ “250-8BITMIME\r\n”
→ “250-SIZE\r\n”
→ “250-DSN\r\n”
→ “250-ETRN\r\n”
→ “250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN\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'
from
./script/…/config/…/config/…/vendor/plugins/action_mailer_tls/lib/smtp_tls.rb:56:in
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’
from
./script/…/config/…/config/…/vendor/rails/actionmailer/lib/action_mailer/base.rb:511:in
perform_delivery_smtp' from ./script/../config/../config/../vendor/rails/actionmailer/lib/action_mailer/base.rb:397:in
deliver!’
from
./script/…/config/…/config/…/vendor/rails/actionmailer/lib/action_mailer/base.rb:291:in
`method_missing’
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.
SWITCHING DELIVERY METHOD
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
bodyport=#TMail::StringPort:id=0x..fdbd0f66e>
In the maillog now I see this:
Feb 3 23:35:39 integrallis sendmail[11957]: l144Zctf011957: Milter add:
header: Received-SPF: pass (integrallis.virtual.vps-host.net: domain of
[email protected] designates 127.0.0.1 as permitted
sender) receiver=integrallis.virtual.vps-host.net; client-ip=127.0.0.1;
helo=integrallis.virtual.vps-host.net;
[email protected];
x-software=spfmilter 0.97 spfmilter with
libspf2-1.0.0;
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=[127.0.0.1] [127.0.0.1],
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, relay=mxmail.register.com.
[205.158.62.41], 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:
mailers:
contact:
subject: Contact Request
from: [email protected]
redirect_to: /en/contact/thank-you
recipients:
- [email protected]
body part:
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
configured)
Processing SiteController#show_page (for 69.218.201.157 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
[http://www.integrallis.com/en/contact]
I’ve search all my other logs but don’t see any errors.
Cheers,
Brian