# Mailer Behaviour... Testing with Rails Console

**URL:** <https://www.ruby-forum.com/t/mailer-behaviour-testing-with-rails-console/84420>\
**Category:** Radiant CMS\
**Created:** [February 4, 2007, 7:38am UTC](https://www.ruby-forum.com/t/mailer-behaviour-testing-with-rails-console/84420 "2007-02-04T07:38:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Sam-Bodden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brian\_Sam-Bodden](https://www.ruby-forum.com/u/Brian_Sam-Bodden)\
**Post date:** [February 4, 2007, 7:38am UTC](https://www.ruby-forum.com/t/mailer-behaviour-testing-with-rails-console/84420/1 "2007-02-04T07:38:25Z")

</div>

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](http://mydomain.com)  
MAIL FROM: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
RCPT TO: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
DATA  
Subject: Test Message  
From: removed\_email\_address@domain.invalid  
To: removed\_email\_address@domain.invalid

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=[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
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 = “removed\_email\_address@domain.invalid”  
> > @from = “removed\_email\_address@domain.invalid”  
> > @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](http://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](http://integrallis.com)\r\n”  
 → “[250-integrallis.virtual.vps-host.net](http://250-integrallis.virtual.vps-host.net) Hello  
[integrallis.virtual.vps-host.net](http://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](http://integrallis.virtual.vps-host.net): domain of  
removed\_email\_address@domain.invalid designates 127.0.0.1 as permitted  
sender) [receiver=integrallis.virtual.vps-host.net](http://receiver=integrallis.virtual.vps-host.net); client-ip=127.0.0.1;  
[helo=integrallis.virtual.vps-host.net](http://helo=integrallis.virtual.vps-host.net);  
envelope-from=removed\_email\_address@domain.invalid;  
x-software=spfmilter 0.97 [spfmilter](http://www.acme.com/software/spfmilter/) with  
libspf2-1.0.0;  
Feb 3 23:35:39 integrallis sendmail[11956]: l144ZcZs011956:  
to=removed\_email\_address@domain.invalid, 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=[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
ctladdr=[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) (0/0), delay=00:00:02,  
xdelay=00:00:01, mailer=esmtp, pri=120418, [relay=mxmail.register.com](http://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: removed\_email\_address@domain.invalid  
redirect\_to: /en/contact/thank-you  
recipients:  
- removed\_email\_address@domain.invalid

# body part:

## Contact us

Your **name** :

Your **email** :

Your **comments** :

- 
- Cancel

# 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”=\>“removed\_email\_address@domain.invalid”},  
“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](http://www.integrallis.com/en/contact)]

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

Cheers,  
Brian
