我是 ruby on Rails 的新手,我读过很多关于这方面的教程,但我仍然不明白出了什么问题。
我已经设置了environment.rb,底部包含以下几行:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 25,
:domain => 'gmail.com',
:authentication => :login,
:user_name => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa7b3a4aba7af8aada7aba3a6e4a9a5a7" rel="noreferrer noopener nofollow">[email protected]</a>',
:password => 'mypassword'
}
然后,我得到了我正在使用的 baseApp 附带的一些代码,它执行以下操作:
UserMailer.deliver_forgot_password(self)
其中 self 是用户对象,包含电子邮件、登录名等。
该方法(属于 UserMailer 类)具有以下代码:
def forgot_password(user)
setup_email(user)
@subject += "Forgotten password instructions"
#{user.password_reset_code}
@body[:url] = "http://#{Setting.get(:site_url)}/users/reset_password/#"
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = "#{Setting.get(:support_name)} <#{Setting.get(:support_email)}>"
@subject = "[#{Setting.get(:site_name)}] "
@sent_on = Time.now
@body[:user] = user
# Get Settings
[:site_name, :company_name, :support_email, :support_name].each do |id|
@body[id] = Setting.get(id)
end
end
嗯,电子邮件很好,我已经检查过它们并进行了 raise 检查,但它没有发送......并且它也没有给我抛出异常。
现在,我在尝试发送电子邮件时收到 Errno::ECONNREFUSED 错误。现在怎么了?
谢谢, 布赖恩
最佳答案
关于ruby-on-rails - 例如,如何使用 gmail 帐户从 ruby 发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1882240/