我在軌道上的紅寶石新,我已經閱讀了很多教程,但我仍然無法弄清楚什麼是錯的。如何使用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