我想用MailGun在Heroku上托管的RubyonRails应用程序中发送电子邮件。在Heroku上使用MailGun for Rails应用程序上的应用程序
我将MailGun插件添加到我的heroku应用程序中。我下面更新我的config/environments/production.rb
:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:port => ENV['MAILGUN_SMTP_PORT'],
:address => ENV['MAILGUN_SMTP_SERVER'],
:user_name => ENV['MAILGUN_SMTP_LOGIN'],
:password => ENV['MAILGUN_SMTP_PASSWORD'],
:domain => 'mydomain.herokuapp.com', #mydomain actually contains the realvalue
:authentication => :plain,
}
我创建了应用程序/邮寄目录中的文件:
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
def notify_user(user)
puts "Going to send email!! to"
puts user
mail(to: user, subject: "Welcome!")
end
end
在我application_controller.rb
我有一个函数:
def notify_people()
puts "Notify people!"
ApplicationMailer.notify_user("[email protected]")
puts "over"
end
从我的其他控制器之一,我打电话给notify_people。但是,在我的heroku日志中,通知人们!正在印刷中,之后没有任何内容。我无法理解为什么它无法调用notify_user。
我notify_user功能是:
类ApplicationMailer <的ActionMailer ::从基地 默认: “[email protected]” #layout '邮件' 高清notify_user(用户) 看跌期权“将发送电子邮件!!到“ 把用户 邮件(到:用户,主题:”欢迎!“) 放入”完成发送邮件!“ 回报 结束 结束
编辑了一些其他的建议:) – thebenedict
我添加了你在我的production.rb文件中提到的命令。我的heroku日志中没有出现任何错误。但是,在打印完邮件之后,它看起来会失败,因为没有任何邮件功能。 – user1692342
您是否能够从应用程序发送电子邮件?你是否用'deliver_later'来呼叫邮件?你在Heroku上面设置了4个环境变量吗?你能确认'notify_user'被执行吗? – thebenedict