Can you only send out email from the username specified in the ActionMailer smtp_settings?
-
05-07-2019 - |
Question
in my ActionMailer config file I have this:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.foo.com",
:port => 25,
:domain => "foo.com",
:authentication => :email,
:user_name => "no-reply@foo.com",
:password => "foo1234567"
}
With this configuration can I only send out email from the no-reply@foo.com
email address? If so is there a way to send out emails from other addresses? I have this in my ActionMailer class:
class Notifications < ActionMailer::Base
def answered_question(faq)
subject 'Your question has been answered'
recipients faq.email
from 'Foo <no-reply@foo.com>'
sent_on Time.now
content_type "text/html"
body :faq => faq
end
def completed_order(order)
subject 'Your order has been completed'
recipients order.email
from 'Foo <registrations@foo.com>'
sent_on Time.now
content_type "text/html"
body :order => order
end
end
In development everything works out fine but in production the completed_order
emails are not being sent out.
Thanks.
Solution
I would guess that this is more of a SMTP issue that it is ActionMailer. Some SMTP's do not require Username/Passwords to send outgoing mail and so you can set the From address as you like.
That said, since you're experiencing issues sending out messages that have a From address different from what you're using to authenticate to your SMTP server, I'd guess there's a restriction on the SMTP box that only allows messages to be sent if the From address matches the authenticating UID.