问题描述
我设法在我的本地机器上配置ActionMailer以通过Gmail发送电子邮件。 (它需要gemfile中的tlsmail)
$ $ p $ $ $ c $ ### config / environment.rb
需要'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(Connection refused - connect(2)))。我搜索了一下,他们对gmail有一个特别的解决方案:
他们在说我需要一个额外的SMTP TLS库。如上所述,我添加了一个解决问题的gem,但只在我的本地机器上解决。好吧,我尝试了他们的解决方案,并在Heroku上运行......但停止了在我的本地工作。 (它没有给出错误,它只是表示电子邮件已发送,但它从来没有。)
环境变量设置正确。
你有什么想法让至少有一种方法可以在我的本地计算机和heroku上运行吗?
Bye 您需要在正确的环境中设置它。您需要在您的gemfile中使用group
完成此操作 group:development do
gem'< development gem这里>'
group:生产do
gem'<这里是生产宝石>'
不要忘记重新包装。然后将与每个环境相关的配置移动到config / environments / production.rb或config / environments.development.rb中。
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
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
这篇关于ROR发送电子邮件heroku,gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!