Ruby On Rails发送邮件的配置

Posted by: bin in Untagged  on Print PDF

ruby on rails 发送邮件配置

一、环境
  ubuntu 9.0.4  ruby 1.8.7 (2008-08-11) [i486-linux]  Rails 2.3

二、目的
   给注册发送激活邮件

三、实现过程
   本想考虑用sendmail,因为RubyOnRails默认情况下就是用sendmail来发送。不过sendmail需要一些复杂的配置,而且人员和系统的用户绑定(也可分开,没有去研究)。
所以,干脆实现用stmp来实现,采用Gmail邮件。
  因为gmail用tls,用先安装插件
  ruby script/plugin install http://svn.xlsuite.org/trunk/vendor/plugins/action_mailer_tls/
  在environment.rb中加入
 config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
   :enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
#:domain => "mycompany.com",
:authentication => :plain,
:user_name => "xxx@gmail.com",
:password => "xxx"
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_charset = 'utf-8'

千万要注意这句,:enable_starttls_auto => true, 不然会出现如下错误
530 5.7.0 Must issue a STARTTLS command first. i6s

因为Rails中具体应用Mail,请参考文档
http://guides.rubyonrails.org/action_mailer_basics.html

回应人次 (0)Add Comment

撰写回应
小一点 | 大一点

busy