我的环境是ruby1.8.7, rails 2.3.5
(1)在environment.rb 加上
(2)
打开model/order.rb
同时在viwers里创建对应的confirm.rhtml
(3)任意打开一个controller
在里面加入
(4)输入地址htto://localhost:3000/controllerName/send_mail,rails就会把confirm.rhtml的内容发送到邮箱
(5)既然方法已经写出来了,其它就剩下自己改了..如密码激活,订单通知之类都是浮云了..当然最好把body部分改为可以直接修改,而不是改页面,那就更好了...
(1)在environment.rb 加上
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_charset = "UTF-8"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true, #不然会出现如下错误530 5.7.0 Must issue a STARTTLS command first. i6s
:address => "smtp.163.com", #使用的邮件服务器
:port => 25, #邮件服务器的端口号
:domain => "163.com", #暂时忽略
:authentication => :login, #不是很清楚,照着写
:user_name => "xxx@163.com", #使用邮件服务器的帐号(这里是google,所以时goole邮箱的帐号)
:password => "xxx" #使用邮件服务器的密码(这里是google,所以时goole邮箱的密码)
#注意: 这里我只是指定了邮件服务器,不是说我指定了google的邮件服务器,就非要使用google的邮箱发送邮件,也可以使用别的邮箱通过google的邮件服务器发送
}
(2)
ruby script/generate mailer order
打开model/order.rb
class Order < ActionMailer::Base
def confirm()
@subject = "hello World"
@body = {'name' => 'dsa'}
@recipients = 'xxx@163.com'
@from = 'xxx@163.com'
@headers = {}
end
end
同时在viwers里创建对应的confirm.rhtml
车车你妹啊
(3)任意打开一个controller
在里面加入
def send_mail
Order.deliver_confirm()
render :text => "success!"
end
(4)输入地址htto://localhost:3000/controllerName/send_mail,rails就会把confirm.rhtml的内容发送到邮箱
(5)既然方法已经写出来了,其它就剩下自己改了..如密码激活,订单通知之类都是浮云了..当然最好把body部分改为可以直接修改,而不是改页面,那就更好了...