Daniel Situnayake
Daniel Situnayake

Reputation: 2904

How to test whether a mail was sent successfully using ActionMailer?

I'm using ActionMailer in Rails 3 to send periodic emails. I need to know whether an email was sent correctly (as far as it is possible to do so).

  @lists.each do |list|
    email = Reminder.deadline_reminder(list)
    email.deliver
  end

Is there a property of the email object (class Mail::message from the Mail library) that will tell me whether the send went correctly (no connection issues, authentication problems, etc)? I've looked through the classes on Github but haven't been able to figure anything out.

Upvotes: 0

Views: 5816

Answers (1)

the Tin Man
the Tin Man

Reputation: 160553

It all depends on what you consider successful.

You can test to see whether your code sent the message. You can often check the log to see if the mail-forwarding host received it and moved it on toward its destination.

But, only proprietary mail systems support delivery-receipts. SMTP doesn't and probably never will because of privacy issues and the inability of the mail-client vendors to agree on how to do it. So, even if it is delivered all the way to the intended destination there's no way to know if the person read it.

Your best bet is to put a link in the message that the user clicks which will tickle an app on the server with a token that was unique for that message. When the app sees the token it sets a flag letting you know they got the message AND at least read the part about clicking the link. Then, if there has to be a response within a given time you also track when the message was sent and escalate if the token wasn't received back within the time-limit.

Upvotes: 4

Related Questions