['vivid]生动的,鲜明的,鲜艳的,大胆的,清晰的,活泼的,逼真的

Let us cling together!

 

在Rails中利用Gmail发送邮件

在Rails1.2中ActionMailer只能用本地的SMTP服务器发送邮件,经过搜索,找到了下面的方法可以用Gmail来发送邮件:

切换到项目目录下,运行:

ruby script/plugin install http://svn.nanorails.com/plugins/action_mailer_tls

这会安装action_mailer_tls插件。

接着,在environment.rb中加入以下代码,启用action_mailer_tls

require "smtp_tls"
mailer_config = File.open("#{RAILS_ROOT}/config/mailer.yml")
mailer_options = YAML.load(mailer_config)
ActionMailer::Base.smtp_settings = mailer_options

在config目录下建立mailer.yml文件,加入邮箱的配置:

:address: smtp.gmail.com
:port: 587
:user_name: xxx@gmail.com
:password: xxxxx
:authentication: :plain

posted on 2009-05-24 21:32  文祥  阅读(286)  评论(0编辑  收藏  举报

导航