rails发送邮件

  1. 在config/environments/development.rb文件中追加邮件设置代码。
  2. 拷贝两个model文件到models目录下。[user_notify.rb,iso2022jp_mailer.rb]
  3. 在user_notify.rb文件中编写发送邮件的代码。
  4. 编写邮件模板。
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
    :address => "xxxxx",
    :domain => "xxxx",
    :port => 25,
    :authentication => :login,
    :user_name => "rails",
    :password => "rails",
}
 
class UserNotify < Iso2022jpMailer
  def ip_not_match(ip, user)
    @recipients    = user.email
    @from          = APP_CONFIG[:from_email]
    @sent_on       = Time.now
    @headers['Content-Type'] = "text/plain; charset=iso2022-JP; format=flowed"
    @subject       = base64("Login Ip not match")
    @body["login"] = user.login
    @body["ip"]    = ip
    @body["last_ip"] = user.ip
  end

end
 
<%= @login %>
	Your login ip not match with last login ip.
	Last IP: <%= @last_ip%>
	This IP: <%= @ip %>

 

 

  def self.send_email(ip, admin)
    UserNotify.deliver_ip_not_match(ip, admin)
  end
 





 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值