2008-06-19
Rails里如何结合ExceptionNotification配置gmail账户发邮件
关键字: exceptionnotification gmail
1,安装ExceptionNotification
光安装这个插件是不能利用gmail发送邮件的,因为gmail需要https,所以还需要安装一个插件
2,安装action_mailer_tls
3,修改exception_notifier.rb,添加一个方法
4,config目录写一个sys_config.rb文件
5,修改environment.rb
好了!,可以在ruby script\console下面试试发送一封email:
ruby script\plugin install http://dev.rubyonrails.org/svn/rails/plugins/exception_notification/
光安装这个插件是不能利用gmail发送邮件的,因为gmail需要https,所以还需要安装一个插件
2,安装action_mailer_tls
ruby script/plugin install http://svn.nanorails.com/plugins/action_mailer_tls
3,修改exception_notifier.rb,添加一个方法
# line 40
def exception_notification
# ...
end
def sys_email(recipients, subject, data={})
subject subject
recipients recipients
from sender_address
body data
end
4,config目录写一个sys_config.rb文件
class SysConfig
EXCEPTION_NOTIFIER = {
:delivery_method => :smtp,
:sender_address => %w(beyondrails@gmail.com),
:email_prefix => "BeyondRails",
:recipients => %w(hideto.bj@gmail.com),
:smtp_settings => {
:address => "smtp.gmail.com",
:port => 587,
:domain => "beyondrails.com",
:authentication => :login,
:user_name => "beyondrails@gmail.com",
:password => "beyondrails@gmail.com的密码"
},
}
end
5,修改environment.rb
# ExceptionNotifier settings ExceptionNotifier.sender_address = SysConfig::EXCEPTION_NOTIFIER[:sender_address] ExceptionNotifier.email_prefix = SysConfig::EXCEPTION_NOTIFIER[:email_prefix] ExceptionNotifier.exception_recipients = SysConfig::EXCEPTION_NOTIFIER[:recipients] ActionMailer::Base.delivery_method = SysConfig::EXCEPTION_NOTIFIER[:delivery_method] ActionMailer::Base.smtp_settings = SysConfig::EXCEPTION_NOTIFIER[:smtp_settings] ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.perform_deliveries = true ActionMailer::Base.default_charset = "utf-8"
好了!,可以在ruby script\console下面试试发送一封email:
ExceptionNotifier.deliver_sys_email("hideto.bj@gmail.com", "email title", "email data.")
评论
D:\InstantRails2.0\rails_apps\gmailtest>ruby script/console
Loading development environment (Rails 2.0.2)
D:/InstantRails2.0/rails_apps/gmailtest/config/environment.rb:16:NameError: uninitialized constant ExceptionNotifier
D:/InstantRails2.0/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:88:NoMethodError: undefined method `cattr_accessor' for ActionController::Dispatcher:Class
D:/InstantRails2.0/rails_apps/gmailtest/app/controllers/application.rb:4:NameError: uninitialized constant ActionController::Base
请问之前遇到过这个错误码 知道如何解决吗
Loading development environment (Rails 2.0.2)
D:/InstantRails2.0/rails_apps/gmailtest/config/environment.rb:16:NameError: uninitialized constant ExceptionNotifier
D:/InstantRails2.0/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:88:NoMethodError: undefined method `cattr_accessor' for ActionController::Dispatcher:Class
D:/InstantRails2.0/rails_apps/gmailtest/app/controllers/application.rb:4:NameError: uninitialized constant ActionController::Base
请问之前遇到过这个错误码 知道如何解决吗
yangzhihuan
2008-06-28
回复
收藏了,小工具,好东西.
发表评论
- 浏览: 723098 次
- 性别:

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
Why OO sucks
看成去QQ SUCK 了
-- by xhanxhanxhan -
Rails的富文本编辑器插件 ...
有没有那个像textmate那种语法高亮的富文本编辑器?
-- by zllicho -
翻译www.djangobook.com之 ...
weiertzw 写道 1. >>> from django. ...
-- by chenjihua75 -
PHP、CakePHP哪凉快哪呆 ...
这孩子被java毒害太深。。。跳出java,你会发现外面的世界真的很大。
-- by woodless -
学习svn命令
只会用 apt-get 不是好孩子。
-- by smartly






评论排行榜