ROR 发送电子邮件 heroku、gmail
我设法在本地计算机上配置 ActionMailer 以通过 Gmail 发送电子邮件。 (它需要 gemfile 中的 tlsmail)
### config/environment.rb
require 'tlsmail'
Ideas::Application.configure do
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => '587',
:domain => '[email protected]',
:user_name => '[email protected]',
:password => 'xxxxxxx',
:authentication => :plain
}
end
这在我的本地计算机上有效(电子邮件已发送),但通常 hreoku 对此有一些问题(Errno::ECONNREFUSED(连接被拒绝 - connect(2)))。我在谷歌上搜索他们有一个针对 gmail 的特殊解决方案:
http://blog.heroku .com/archives/2009/11/9/tech_sending_email_with_gmail/
他们说我需要一个额外的 SMTP TLS 库。如上所述,我添加了一个 gem 来解决该问题,但仅限于我的本地计算机。好吧,我尝试了他们的解决方案,它在 Heroku 上有效,但在我的本地停止工作。 (它不会给出错误,它只是说电子邮件已发送,但从未发送过。)
环境变量设置正确。
您是否有任何想法如何使至少其中一种方法在我的本地计算机和 Heroku 上都有效?
再见
I managed to configure ActionMailer on my local machine to send emails via Gmail. (it required tlsmail in gemfile)
### config/environment.rb
require 'tlsmail'
Ideas::Application.configure do
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => '587',
:domain => '[email protected]',
:user_name => '[email protected]',
:password => 'xxxxxxx',
:authentication => :plain
}
end
This worked on my local machine (the emails were sent) but as usually hreoku had some problems with this (Errno::ECONNREFUSED (Connection refused - connect(2))). I googled that they have a particular solution for gmail:
http://blog.heroku.com/archives/2009/11/9/tech_sending_email_with_gmail/
They are saying I need an additional SMTP TLS library. As mentioned above I added a gem that resolved the issue but only on my local machine. Well ok, I tried their solution and it worked... on heroku, but stopped working on my local. (it doesn't give an error, it just says the email was sent, but it never is.)
Environmental variables are set properly.
Do you have any ideas how to make at least one of this methods work both on my local machine and heroku?
Bye
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将其设置在正确的环境中。您需要在 gemfile 中使用组来执行此操作,
不要忘记重新捆绑。然后将与每个环境相关的配置移动到 config/environments/development.rb 或 config/environments.development.rb 中
You need to set it up in the correct environment. You'll need to do this in your gemfile with groups
Don't forget to rebundle. Then move the config relevant to each environment into either config/environments/production.rb or config/environments.development.rb