environment.rb里配置
require "smtp_tls"
ActionMailer::Base.delivery_method = :smtp
#以简单邮件传送协议发送邮件
ActionMailer::Base.default_charset = "GBK"
#设置邮件的默认编码为国标码否则发送的邮件主题可能会乱码
ActionMailer::Base.server_settings = {
:address => "smtp.gmail.com",
:port => 587,
#:domain => "www.gmail.com",
:authentication => :plain,
:user_name => "username",
:password => "password",
}
生成mailer类..的方法
def confirm(email, sent_at = Time.now)
@subject = 'Welcome to Beast'
@body = "hello world"
@recipients = email
@from = '
[email protected]'
@sent_on = sent_at
@headers = {}
end
然后在controller里调用发送邮件
OrderMailer.create_confirm(email) 用这个能够建立邮件对像。。
OrderMailer.deliver_confirm(email)
用这个发送邮件没反应哦。。不知道是怎么回事。。