我正在尝试使用以下配置发送电子邮件
config.action_mailer.default_url_options = { :host => 'lototribe.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => '465',
:domain => 'lototribe.com',
:user_name => 'no-reply@lototribe.com',
:password => 'password',
:authentication => :plain,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
抛出一个Net :: ReadTimeout。 Om检查我发现的堆栈跟踪
smtp.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication]) do |smtp_obj|
response = smtp_obj.sendmail(message, smtp_from, smtp_to)
end
其中
>> settings[:domain]
=> "localhost.localdomain"
>> settings[:user_name]
=> nil
>> settings[:password]
=> nil
>> settings[:authentication]
=> nil
这些是从未预料到的值。 任何人都可以说出为什么这些值错误地设定了吗?
答案 0 :(得分:0)
尝试将.perform_deliveries设置为true并将ActionMailer :: Base声明更改为config.actionmailer,如下所示:
config.action_mailer.raise_delivery_errors = false
host = ENV['EMAIL_DOMAIN']
config.action_mailer.default_url_options = { host: host}
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.zoho.com",
:port => 587,
:user_name => ENV["USERNAME"],
:password => ENV["PASSWORD"],
:authentication => :plain,
:enable_starttls_auto => true
}
我想做的另一个想法是在发送电子邮件时发现任何错误,因为发送电子邮件的结果几乎总是在某种时间类型的错误中。我拯救它,以便即使有些失败也能发送电子邮件:
MyMailer.send_email(subject: subject, user: user, message: message).deliver
rescue Net::OpenTimeout, Net::ReadTimeout, Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e
Rails.logger.error e.message
end