我在轨道上的红宝石新,我已经阅读了很多教程,但我仍然无法弄清楚什么是错的。如何使用Gmail帐户从ruby发送电子邮件,例如?
我已经成立的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 => '[email protected]',
:password => 'mypassword'
}
然后,我有一个与我使用的baseApp传来了一些代码,并执行以下操作:
UserMailer.deliver_forgot_password(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
嗯,电子邮件都很好,我已经检查他们做检查提高,但它不发送......,并没有任何扔给我一个例外。
现在我在尝试发送电子邮件时收到Errno :: ECONNREFUSED错误。现在有什么问题?
感谢, 布赖恩
您使用的是哪种版本的导轨? – Mark 2009-12-10 17:20:08
毫米,如果我右键点击项目,我会看到Ruby平台:内置JRuby 1.2.0。那是你想知道的吗? – 2009-12-10 17:56:35