有没有办法在heroku上使用sendgrid调试邮件程序?或者检查邮件是否实际发送?
我正在尝试在我的 Rails 3.0.10 项目上实现“联系我们”表单。按照 RailsGuides 我创建了一个邮件程序。
class QuestionMailer < ActionMailer::Base
default :to => "%mail@mydomain" #gmail for domains
def ask(message)
@content = message.content
unless message.name.nil? or message.name.empty?
from = "#{message.name} <#{message.email}>"
else
from = message.email
end
mail(:subject => message.subject, :from => from)
end
end
在我的控制器中,我有这些行:
if @question.valid?
QuestionMailer.ask(@question).deliver
redirect_to root_url, :notice => "Сообщение отправлено"
else
Production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '%mydomain%' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN']
}
我一开始没有这个配置,但是当我没有收到电子邮件时,我添加了它。
问题是,Heroku 日志显示,相应的视图已呈现,但我没有收到电子邮件。而且因为我使用sendgrid,所以无法在本地测试。
更新
自我注释。为域帐户创建 Gmail 后,不要忘记您的 DNS 设置。 >_<
I'm trying to implement a "contact us" form on my rails 3.0.10 project. Following the RailsGuides I created a mailer.
class QuestionMailer < ActionMailer::Base
default :to => "%mail@mydomain" #gmail for domains
def ask(message)
@content = message.content
unless message.name.nil? or message.name.empty?
from = "#{message.name} <#{message.email}>"
else
from = message.email
end
mail(:subject => message.subject, :from => from)
end
end
In my controller I have these lines:
if @question.valid?
QuestionMailer.ask(@question).deliver
redirect_to root_url, :notice => "Сообщение отправлено"
else
Production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '%mydomain%' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN']
}
I didn't have this config at first, but when I didn't receive the email, I added it.
The problem is, the Heroku log says, that the corresponding view has been rendered, but I don't receive the email. And because I use sendgrid, I cant test it locally.
upd
Note to self. After creating gmail for domain account, don't forget to your DNS settings. >_<
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您仍然可以使用 sendgrid 在本地进行测试 - 从命令行执行
heroku config
,您可以获取 Heroku 为 sendgrid 用户名、密码和域设置的值,然后将它们与development.rb 一起设置actionmailer 设置,它会从本地开发应用程序通过 sendgrid 路由您的消息。我还找到了这个heroku插件 https://github.com/hone/heroku-sendgrid-stats 对于检查我的消息发送号码非常有用。
You can test locally still using sendgrid - from the command line do
heroku config
and you can grab the values that Heroku has set for sendgrid username, password and domain and then set them in your development.rb along with the actionmailer settings and it will route your message through sendgrid from your local development app.I also find this heroku plugin https://github.com/hone/heroku-sendgrid-stats very useful for checking on my message sending numbers.