- 论坛徽章:
- 0
|
ActionMailer的一些配置
.一般情况下,如果你使用gmail的话,都是这样配置的:
Ruby代码- ActionMailer::Base.smtp_settings = {
- :address => "smtp.gmail.com",
- :port => 587,
- :domain => "your_domain.com",
- :user_name => "your_name@gmail.com",
- :password => "xxxxxxx",
- :authentication => :login,
- :enable_starttls_auto => true
- }
复制代码 但更使用gmail发送的话,要注意gmail是有发送限制的,一般都是一天之内发送500封邮件,另外好像频繁连接或者出错的话,gmail会要求你登陆的时候输入验证码,如果你检查配置无误,但是无论如何都发不了邮件,多半就是这个验证码或者达到了发送邮件上限的问题了。
如果你想使用服务器自带的sendmail程序来发送email的话,可以这样配置:
Ruby代码- ActionMailer::Base.delivery_method = :sendmail
- ActionMailer::Base.sendmail_settings = {
- :location => '/usr/sbin/sendmail',
- :arguments => '-i -t'
- }
复制代码 至于如何安装sendmail,请google之,我从鸟哥那本Linux服务器的书上看到了详细的教程和一般解决问题的方法,推荐看看。
在Rails的console里面就可以测试发送Email,这是一个非常有用的功能:
Ruby代码- class SystemMailer < ActionMailer::Base
- def test
- mail(:to => "your_name@gmail.com",:body => "Have a good day!", :subject => "test mail")
- end
- end
复制代码 打开 console
Ruby代码- 1.rails c
- 2.
- 3.#输入如下代码
- 4.SystemMailer.test.deliver
复制代码 |
|