我使用的是Rails 5。我在config/environment/development.rb和config/environment/staging.rb中有以下配置。
config/environment/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
当我调用发送电子邮件的方法时,我得到以下输出。
Rendering mailer/consolidated_s3_storage_report.html.erb
Rendered mailer/consolidated_s3_storage_report.html.erb (0.4ms)
Mailer#consolidated_s3_storage_report: processed outbound mail in 17668.1ms
=> #<Mail::Message:86763960, Multipart: true, Headers: <From: mcds@sheridan.com>, <To: mcds.support@sheridan.com>, <Subject: 2017 July - S3 Storage Report>, <Mime-Version: 1.0>, <Content-Type: multipart/mixed; boundary="--==_mimepart_595c962cc36fb_1be1b2198436941"; charset=UTF-8>>
但电子邮件不会发送到我的gmail。“发件人”地址是发送所有其他电子邮件的“默认发件人”。请澄清为什么我的电子邮件没有送达。
发布于 2017-07-05 15:44:31
您似乎正在使用Mailcatcher。邮件捕手不投递邮件,它的目的是阻止邮件投递到实际的To
电子邮件地址,但可以让你检查邮件是否被正确封装。开发人员在开发环境中使用Mailcatcher来查看电子邮件是否呈现为他们期望的样子,而不会向To
电子邮件持有者发送垃圾邮件。
所有发送到Mailcatcher的电子邮件都可以在web界面中查看。在您的计算机上访问http://localhost:1080
,您应该能够看到到目前为止从开发环境中发送的所有电子邮件。
发布于 2017-07-05 15:57:02
以下是向gmail发送邮件的配置:
config/environment/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "user@gmail.com", #your gmail id
:password => "password", #your gmail password
:authentication => "plain",
:enable_starttls_auto => true
}
https://stackoverflow.com/questions/44919843
复制相似问题