1,安装ExceptionNotification
[code]
ruby script\plugin install http://dev.rubyonrails.org/svn/rails/plugins/exception_notification/
[/code]
光安装这个插件是不能利用gmail发送邮件的,因为gmail需要https,所以还需要安装一个插件
2,安装action_mailer_tls
[code]
ruby script/plugin install http://svn.nanorails.com/plugins/action_mailer_tls
[/code]
3,修改exception_notifier.rb,添加一个方法
[code]
# line 40
def exception_notification
# ...
end
def sys_email(recipients, subject, data={})
subject subject
recipients recipients
from sender_address
body data
end
[/code]
4,config目录写一个sys_config.rb文件
[code]
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
[/code]
5,修改environment.rb
[code]
# 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"
[/code]
好了!,可以在ruby script\console下面试试发送一封email:
[code]
ExceptionNotifier.deliver_sys_email("hideto.bj@gmail.com", "email title", "email data.")
[/code]
[code]
ruby script\plugin install http://dev.rubyonrails.org/svn/rails/plugins/exception_notification/
[/code]
光安装这个插件是不能利用gmail发送邮件的,因为gmail需要https,所以还需要安装一个插件
2,安装action_mailer_tls
[code]
ruby script/plugin install http://svn.nanorails.com/plugins/action_mailer_tls
[/code]
3,修改exception_notifier.rb,添加一个方法
[code]
# line 40
def exception_notification
# ...
end
def sys_email(recipients, subject, data={})
subject subject
recipients recipients
from sender_address
body data
end
[/code]
4,config目录写一个sys_config.rb文件
[code]
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
[/code]
5,修改environment.rb
[code]
# 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"
[/code]
好了!,可以在ruby script\console下面试试发送一封email:
[code]
ExceptionNotifier.deliver_sys_email("hideto.bj@gmail.com", "email title", "email data.")
[/code]