配置ActionMailer使用GMail傳送郵件
這個問題由來已久,比較了一下幾種現有的解決方案,最後發現Robert Bousquet的方案是最簡單的。
1. Robert只提供了一個原始碼下載連結,不是很方便,我將它放到了github上:
$ script/plugin install git://github.com/yzhang/smtp_tls.git
2. 修改environment.rb:
require "smtp_tls"
mailer_config = File.open("#{RAILS_ROOT}/config/mailer.yml")
mailer_options = YAML.load(mailer_config)
ActionMailer::Base.smtp_settings = mailer_options
3. 建立config/mailer.yml
—
:address: smtp.gmail.com
:port: 587
:user_name: john@doe.com
:password: s1j234gh
:authentication: :plain
4. 如果你使用了ExceptionNotification外掛,那麼你需要確保ExceptionNotification的發件人設定與你的Gmail帳戶相符,否則GMail將會拒絕傳送。
摘自:www.letrails.cn