Mailer Setup Problems

I’m having trouble configuring a mailer. Prudence would dictate that
I should upload at least portions of the relevant files, etc. If it
comes to that, I’ll certainly do it. However, before I go that route I
would really like to see if I can’t use this problem to develop some
trouble shooting skills because I know that I’m going to need them in
the future.

Basically the situation is that I have followed the general setup
detailed in ‘Agile Web D. with Rails’. Amongst other things I
have specifically included the line:

config.action_ mailer.delivery_ method=:sendmail

in my config/environments/test.rb file and /usr/sbin/sendmail is a sym
link to my sendmail-compatible smtp server. The single symptom is that
the email doesn’t actually get sent. Otherwise, the whole process
completes exactly as one would expect. There are no indications of
problems logged to either the rails log file or the log file of my
smtp server. The fact that nothing is logged to the log file of my
smtp server makes me believe that it is not actually receiving a
request.

So, my question is this: Given this fact pattern how should I proceed
in order to isolate and correct the problem?

Thanks for any input.

     ... doug

doug wrote:

So, my question is this: Given this fact pattern how should I proceed
in order to isolate and correct the problem?

Are you running the application in development mode?

If so, take a look at the last line in
config/environments/development.rb.

–Al Evans

Are you running the application in development mode?

No. I’m running in test mode. I’ve gotten this thing to
work before in test mode; but, not this time. The issue
I’m trying to address is: What does one do when
something like this happens. I’m thinking that there
must be some sort of troubleshooting procedure to
follow.

Thanks for the input.

   ... doug

doug wrote:

Are you running the application in development mode?

No. I’m running in test mode. I’ve gotten this thing to
work before in test mode; but, not this time. The issue
I’m trying to address is: What does one do when
something like this happens. I’m thinking that there
must be some sort of troubleshooting procedure to
follow.

Thanks for the input.

   ... doug

OK, different config, same result –

From config/environments/test.rb:

Tell ActionMailer not to deliver emails to the real world.

The :test delivery method accumulates sent emails in the

ActionMailer::Base.deliveries array.

config.action_mailer.delivery_method = :test

So it’s doing what it’s configured to do.

–Al Evans

On May 26, 10:45 pm, doug [email protected] wrote:

What does one do when
something like this happens. I’m thinking that there
must be some sort of troubleshooting procedure to
follow.

What I generally do is to first try the obvious. Step through the code
mentally looking for any obvious mistakes. I catch most of my errors
this way. If that doesn’t work, sometimes you can use debug logging to
validate your assumptions. Spit out the value of variables, write a
log entry when you enter a function to make sure you’re actually
entering it, etc.

When the above fails (actually I usually go to this next, before I
bother with the logging thing), the best thing you can do for yourself
is to use a decent debugger. The value of having a good debugger at
your disposal - and using it - cannot be overstated. They can save you
many many minutes of head-scratching time. Sometimes hours. I can’t
tell you the number of times I’ve figured out an issue with a debugger
in a few minutes that I’m sure would have taken me hours to figure out
without one.

For my money (which is sort of a misnomer, because this one’s free),
the best Ruby/Rails debugger available right now is the one in
NetBeans 6. If you’ve used a debugger with Java or C++ or other
languages before, this one works pretty much the same. If you haven’t,
now is the time to learn how. :slight_smile: Don’t worry, it really isn’t hard.
It’s pretty easy to get started, and just takes some practice to
become proficient.

I strongly recommend downloading NetBeans 6 M9 and running your
project inside of its debugger. Set a breakpoint on the line where you
send the mail, and when you hit it, start stepping through the code
line by line, inspecting variables and watching where the execution
path goes along the way. You’ll find your problem. Make sure you
switch NetBeans from using JRuby to using your native Ruby
interpreter, and see this page for setting up the fast debugger:

http://wiki.netbeans.org/wiki/view/RubyDebugging

You wanted to know what developers usually do when things don’t work
as expected - this is it. We turn to our debuggers to help us find out
why.

Hope that helps. Feel free to ping back with questions. And good
luck. :slight_smile:

Thanks, Bill, for the thorough response. Your point is well
taken about the debugger. A debugger is an invaluable tool
to be used as a debugging AID after one has completed
the first step that you described which is:

Step through the code
mentally looking for any obvious mistakes.

The problem I’m having with Rails is that I don’t know what
code to step through. I read these instructions on how to make
the mailer work. I follow them and when it doesn’t work, I have
no idea what to do. This has got to be an easy thing. I can
send a test e-mail very simply using the following shell script:

#!/bin/bash
/usr/sbin/sendmail -t <<_ALTO
To: [email protected]
From: [email protected]
Subject: Test

Now is the time
for all good men
to come to the aid
of their party.
_ALTO

That tells me that I have my smtp server correctly configured
for this task. So, it seems to me that the next step would be
to somehow test to see whether the outgoing e-mail is actually
being generated and transferred to the smpt server. It appears
that that isn’t happening. I would really expect there to be some
log entry telling me that something has failed. You have
mentioned ‘debug logging’. I wasn’t aware that there was such
a thing. Presumably that advances the logging level. I’ll look
into that as that may be the key to solving my problem.

Thanks for the input.

   ... doug

~

So it’s doing what it’s configured to do.

Good point, and maybe this is something I need to look into because
that’s exactly how it’s behaving. That is to say that it’s behaving
as though it were in testing mode and not actually sending the e-
mail. However, what I MEANT was that I’m running in the testing
ENVIRONMENT. I do have:

config.action_ mailer.delivery_ method=:sendmail

Thanks for the input.

    ... doug

On May 27, 1:02 pm, doug [email protected] wrote:

Step through the code
mentally looking for any obvious mistakes.

The problem I’m having with Rails is that I don’t know what
code to step through.

I meant stepping through the code you wrote. Not necessarily Rails
code (although the debugger will take you in there if you use it; you
won’t have to know what Rails code to look at, the debugger will).

You have
mentioned ‘debug logging’. I wasn’t aware that there was such
a thing. Presumably that advances the logging level. I’ll look
into that as that may be the key to solving my problem.

Actually I was talking about adding logging statements to your code,
such as “some_variable is currently #{some_variable}” in order to see
what’s going on without necessarily using a debugger (which can tell
you all the same things and then some). However, now that you mention
it, there is such a thing as debug logging. It’s already turned on by
default if you’re running in development mode, but you can enable it
for other modes by putting this in your environment.rb file:

config.log_level = :debug