【发布时间】:2016-05-22 10:16:10
【问题描述】:
在开发环境中提交表单后,应用程序会向我的电子邮件地址发送一封电子邮件。在生产环境中,Heroku 日志报告正在发送电子邮件,但是当我检查邮箱时,电子邮件不存在。这是我的配置:
application.yml
GMAIL_USERNAME: "christopherpelnar@gmail.com"
GMAIL_PASSWORD: "sevenmississippi"
user_mailer.rb
class UserMailer < ApplicationMailer
default from: "christopherpelnar@gmail.com"
def customer_email(message)
@message = message
mail(to: "christopherpelnar@gmail.com", subject: "Message from your website" )
end
end
messages_controller.rb
def create
@message = Message.new(message_params)
if @message.save
UserMailer.customer_email(@message).deliver_now
redirect_to '/message_sent'
else
redirect_to '/'
end
end
production.rb
config.action_mailer.default_url_options = { :host => 'stormy-wildwood-29407.herokuapp.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
Heroku 日志
2016-05-22: UserMailer#customer_email: processed outbound mail in 238.2ms
2016-05-22: Sent mail to christopherpelnar@gmail.com (158.2ms)
2016-05-22:
2016-05-22: Date: Sun, 22 May 2016 09:43:29 +0000
2016-05-22: From: christopherpelnar@gmail.com
2016-05-22: To: christopherpelnar@gmail.com
2016-05-22: Message-ID: <17f4181751_3.mail>
2016-05-22: Subject: Message from your website
2016-05-22: Mime-Version: 1.0
2016-05-22: Content-Type: text/html;
2016-05-22: charset=UTF-8
2016-05-22: Content-Transfer-Encoding: 7bit
问题仅在生产中,通过 localhost:3000 发送没有问题
【问题讨论】:
-
你在 Heroku 上设置环境变量了吗?访问:Setting Environment Variables on Heroku.
-
解决了这个问题。我在控制台中运行了
heroku config,变量与我在 application.yml 中的变量不同。如果您想以答案的形式提交此内容,我很乐意为您提供信用。
标签: ruby-on-rails ruby heroku gmail