ActionMailer smtp_settingsで指定されたユーザー名からのみメールを送信できますか?
-
05-07-2019 - |
質問
ActionMailerの設定ファイルには次のようなものがあります:
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"
}
この構成では、 no-reply@foo.com
メールアドレスからのみメールを送信できますか?もしそうなら、他のアドレスからメールを送信する方法はありますか? ActionMailerクラスにこれがあります:
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
開発中はすべて正常に機能しますが、本番環境では completed_order
メールは送信されません。
ありがとう。
解決
これは、ActionMailerであるというよりSMTPの問題だと思います。一部のSMTPは、送信メールの送信にユーザー名/パスワードを必要としないため、Fromアドレスを自由に設定できます。
とはいえ、SMTPサーバーへの認証に使用しているものとは異なる差出人アドレスを持つメッセージの送信で問題が発生しているので、SMTPボックスにはメッセージの送信のみを許可する制限があると思います差出人アドレスが認証UIDと一致する場合に送信されます。
所属していません StackOverflow