2012-10-14 130 views

回答

88

http://lindsaar.net/2010/3/15/how_to_use_mail_and_actionmailer_3_with_gmail_smtp

要通过Gmail发送出去,你需要配置Mail::SMTP类有正确的价值观,所以尝试了这一点,开拓IRB并键入以下内容:

require 'mail' 

options = { :address    => "smtp.gmail.com", 
      :port     => 587, 
      :domain    => 'your.host.name', 
      :user_name   => '<username>', 
      :password    => '<password>', 
      :authentication  => 'plain', 
      :enable_starttls_auto => true } 



Mail.defaults do 
    delivery_method :smtp, options 
end 

最后一个块调用Mail.defaults,它允许我们为从现在开始创建的所有邮件对象设置全局交付方法。高级用户提示,您不必使用全局方法,您可以直接在任何个人对象上定义delivery_method,并且每封电子邮件都有不同的传送代理,如果您正在构建具有多个用户且具有不同服务器的应用程序处理他们的邮件。

Mail.deliver do 
       to '[email protected]' 
     from '[email protected]' 
  subject 'testing sendmail' 
     body 'testing sendmail' 
end 
+0

谢谢西蒙娜工作 –

+0

Upvote。非常感谢Mikel。 – orde

+3

我收到以下错误:'/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/smtp.rb:960:in'check_auth_response':534- 5.7.14 janosrusiczki

相关问题