2017-04-18 35 views
0

我想有以下配置的ActionMailer值未设置

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   => '[email protected]', 
:password    => 'password',   
:authentication  => :plain, 
:ssl     => true, 
:tls     => true, 
:enable_starttls_auto => true  
} 

投掷的Net :: ReadTimeout发送电子邮件。嗡检查堆栈跟踪,我发现

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

尝试设置.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