免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2847 | 回复: 1
打印 上一主题 下一主题

ActionMailer的一些配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-17 21:56 |只看该作者 |倒序浏览
ActionMailer的一些配置



.一般情况下,如果你使用gmail的话,都是这样配置的:

Ruby代码
  1. ActionMailer::Base.smtp_settings = {
  2.   :address              => "smtp.gmail.com",
  3.   :port                 => 587,
  4.   :domain               => "your_domain.com",
  5.   :user_name            => "your_name@gmail.com",
  6.   :password             => "xxxxxxx",
  7.   :authentication       => :login,
  8.   :enable_starttls_auto => true
  9. }
复制代码
但更使用gmail发送的话,要注意gmail是有发送限制的,一般都是一天之内发送500封邮件,另外好像频繁连接或者出错的话,gmail会要求你登陆的时候输入验证码,如果你检查配置无误,但是无论如何都发不了邮件,多半就是这个验证码或者达到了发送邮件上限的问题了。

如果你想使用服务器自带的sendmail程序来发送email的话,可以这样配置:

Ruby代码
  1. ActionMailer::Base.delivery_method = :sendmail
  2. ActionMailer::Base.sendmail_settings = {
  3.   :location       => '/usr/sbin/sendmail',
  4.   :arguments      => '-i -t'
  5. }

复制代码
至于如何安装sendmail,请google之,我从鸟哥那本Linux服务器的书上看到了详细的教程和一般解决问题的方法,推荐看看。

在Rails的console里面就可以测试发送Email,这是一个非常有用的功能:

Ruby代码
  1. class SystemMailer < ActionMailer::Base
  2.   def test
  3.      mail(:to => "your_name@gmail.com",:body => "Have a good day!", :subject => "test mail")
  4.   end
  5. end
复制代码
打开 console

Ruby代码
  1. 1.rails c   
  2. 2.  
  3. 3.#输入如下代码   
  4. 4.SystemMailer.test.deliver  
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-08-18 22:33 |只看该作者
以后标出Rails什么版本吧?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP