26th Nov, 2008

配置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将会拒绝发送。

评论

我也一直在使用这个方案(外加其他几种方案,呵呵)。另外,tlsmail gems也以有满足需要。

Rails 2.2 不需要,可以直接发送了吧

另外有SVN源 http://svn.nanorails.com/plugins/action_mailer_tls

这个方法以前做网站的时候用过,虽然还不错,不过gmail本身的限制是难以客服的,我记得是一天只能发50封信,对于网站来说限制比较大

留条评论?

Your response:

Categories