我正在运行rails 4.2并设置了一个rake任务来发送电子邮件,但在运行rake任务时出现此错误:
** Invoke send_report_email (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute send_report_email
production
rake aborted!
OpenSSL::SSL::SSLError: hostname "localhost" does not match the server certificate
/usr/lib/ruby/2.2.0/openssl/ssl.rb:240:in `post_connection_check'
/usr/lib/ruby/2.2.0/net/smtp.rb:588:in `tlsconnect'
/usr/lib/ruby/2.2.0/net/smtp.rb:563:in `do_start'
/usr/lib/ruby/2.2.0/net/smtp.rb:520:in `start'
/var/lib/gems/2.2.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
/var/lib/gems/2.2.0/gems/mail-2.6.3/lib/mail/message.rb:252:in `deliver!'
/var/lib/gems/2.2.0/gems/actionmailer-4.2.3/lib/action_mailer/message_delivery.rb:77:in `deliver_now!'
/var/lib/gems/2.2.0/gems/actionmailer-4.2.3/lib/action_mailer/message_delivery.rb:95:in `deliver!'
/path/to/app/lib/tasks/email_tasks.rake:4:in `block in <top (required)>'
/usr/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/usr/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/usr/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/usr/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/usr/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/usr/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/usr/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/usr/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/usr/bin/rake:33:in `<main>'
Tasks: TOP => send_report_email
行production
只是我在rake任务中有一个put ENV["RAILS_ENV"]
,以确保它被设置为生产
我的/config/enviroments/production.rb
config.action_mailer_default_url_options = {host: "my.host.com"}
config.action_mailer_smtp_settings = {
enable_starttls_auto: false,
domain: 'my.host.com',
address: "my.host.com",
openssl_verify_mode: 'none'
}
当我运行apt-get install postfix
时,我还将其配置为使用my.host.com
而不是localhost。 rails从哪里获取localhost值?