notification on email delivery failure with action mailer in rails
When I send an email to someone with action mailer in a rails 3 project
mail(:to => @email, :subject=> "subject")
Is it possible for the controller to get notified if the message was delivered pr开发者_开发问答operly to the :to email address ,so that it will be possible to notify the sender about the email notification failure ?
Thanks.
You can't check to see if somebody's received an email, but you can check to see if they've opened it. Email services these days use a small 1x1px image which contains some values in the query parameters to associate it to the user.
Other than that, no.
The deliver operation applied to a mail object will raise an error if the mail service it uses (e.g. mailgun) refuses it. I assume it's possible to rescue that error but haven't succeeded yet.
ActionMailer does not do this inherently, but using a 3rd party delivery service like MailChimp will let you query their API (mandrill) and seek the delivery and 'opened' confirmations.
You could then extend ActionMailer to include hooks for these APIs and thereby-get notification. The operation will be highly-asynchronous, and I'm not used to people storing and re-instantiating an ActionMailer object. Feedback on that is welcome.
精彩评论