发送邮件需要SMTP地址

时间:2014-06-24 14:28:29

标签: ruby-on-rails devise actionmailer

我正在尝试使用Devise发送重置密码电子邮件。

错误:

: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
from /app/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/check_delivery_params.rb:9:in `check_delivery_params'
from /app/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:98:in `deliver!'
from /app/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
from /app/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:234:in `deliver'
from (irb):27
from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'

我尝试手动构建邮件对象:

mail = Mail.new do
  from    'name@mydomain.com'
  to      'name@mydomain.com'
  subject 'This is a test email'
  body    File.read('body.txt')
end

并且正在运行mail.smtp_envelope_to会返回[]。当我运行mail.To = 'name@mydomain.com', mail.smtp_envelope_to returns [“name@mydomain.com”]时。

为什么我收到此错误?

编辑:SMTP_SETTINGS

if Rails.env.staging? || Rails.env.production?
  SMTP_SETTINGS = {
    address: ENV['SMTP_ADDRESS'], # example: 'smtp.sendgrid.net'
    authentication: :plain,
    domain: ENV['BASE_URL'], # example: 'this-app.com'
    password: ENV['SENDGRID_PASSWORD'],
    port: '587',
    user_name: ENV['SENDGRID_USERNAME']
  }
end
编辑:缺少的引用是一个糟糕的重新类型。请参阅我的Rails代码的SMTP_SETTINGS。第一个代码块是我尝试从控制台重现邮件错误。

1 个答案:

答案 0 :(得分:0)

从我认为已移除的吊杆中取出宝石,接收器拦截器被留下。

删除修复问题。