ROR 发送电子邮件 heroku、gmail

发布于 2024-11-28 03:24:23 字数 1317 浏览 1 评论 0原文

我设法在本地计算机上配置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永言不败 2024-12-05 03:24:23

您需要将其设置在正确的环境中。您需要在 gemfile 中使用组来执行此操作,

group :development do
  gem '<development gem here>'

group :production do
  gem '<production gem here>'

不要忘记重新捆绑。然后将与每个环境相关的配置移动到 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

group :development do
  gem '<development gem here>'

group :production do
  gem '<production gem here>'

Don't forget to rebundle. Then move the config relevant to each environment into either config/environments/production.rb or config/environments.development.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文