devroom.io/content/posts/2007-06-20-action-mailer-all-mail-comes-from-mailer-daemon.md

33 lines
1.1 KiB
Markdown
Raw Normal View History

2015-03-26 11:28:08 +00:00
+++
date = "2007-06-20"
title = "Action Mailer: All mail comes from MAILER DAEMON"
tags = ["General", "RubyOnRails", "Features", "Ruby"]
slug = "action-mailer-all-mail-comes-from-mailer-daemon"
2017-09-11 12:20:15 +00:00
description = "How to configure ActionMailer properly for sending email"
2015-03-26 11:28:08 +00:00
+++
2017-03-20 15:35:19 +00:00
Today I was trying to send mail from my Rails application through Action Mailer. This is quite simple, but I
wanted to use a custom from-address. So, I create a setup_email method in my UserNotifier class that sets
some defaults for every email sent out:
``` ruby
class UserNotifier < ActionMailer::Base
2015-03-26 11:28:08 +00:00
protected
def setup_email(user)
@recipients = "#{user.email}"
2017-03-20 15:35:19 +00:00
@from = "My Application <no-reply@example.com>">
2015-03-26 11:28:08 +00:00
end
2017-03-20 15:35:19 +00:00
end
```
2015-03-26 11:28:08 +00:00
May you spotted the problem already, but I didn't. All the mail sent came from "MAILER DAEMON".
2017-03-20 15:35:19 +00:00
``` text
From: MAILER DAEMON
```
2015-03-26 11:28:08 +00:00
The problem was that @from didn't contain a properly formated from-address. It is missing the closing >, and so my email server ignores it.
If you have this issue, double check the from address, and make sure it's valid! Cheers.