rails send mail set from name

Posted by wxianfeng Thu, 17 Sep 2009 17:14:00 GMT

效果

以前 用 google 的 smtp 服务 成功发送了 email.

http://www.blogjava.net/fl1429/archive/2009/05/04/268866.html

由于 google 的 smtp 每天只容许 发送 500 封email,所以必须自己搭建邮件服务器了。。。。邮件服务器用的是 kerio mail server , 搭好之后 enviroment.rb 中 配置

ActionMailer::Base.perform_deliveries = true
 ActionMailer::Base.raise_delivery_errors = true
 ActionMailer::Base.default_charset = "utf-8"
 ActionMailer::Base.default_content_type = "text/html"
 ActionMailer::Base.smtp_settings = {
     :address => "59.314.13.266",
     :port => 25,
     :domain => "www.abc.com",
     :user_name => "webmaster",
     :password => "riskfit654321",
     :authentication => :login
     }

Model里的send 方法

  def send_password(recipient, subject, name,password)
    @subject = subject 
    @recipients = recipient 
    @from = 'webmaster@abc.com'
    @sent_on = Time.now   
    @body["name"] = name 
    @body['password'] = password 
    @headers = {}
  end

可是 发送 email 后 , 邮箱 显示的发件人 始终是 webmaster , 那么 我 想让发件人的名字显示成 测试 , 该如何设置呢,那么把@from 设置成这样 :

@from = '"测试"<webmaster@abc.com>' # 主意是外面是单引号 , 里面 是 双引号 ,而且用户名webmaster 必须和 config里的user_name 一样

ref:

http://www.javaeye.com/topic/126875

This entry was posted on Thu, 17 Sep 2009 17:14:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags ,


Trackbacks

Use the following link to trackback from your own site:
http://wxianfeng.com/trackbacks?article_id=3

Comments

Leave a comment