`
netfork
  • 浏览: 481109 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Rails 2.3.3,没事你改mail.from干么,真服了,浪费我一天时间

    博客分类:
  • Ruby
阅读更多
今天想实现发邮件时,接收到的邮件是显示发件人的名,而不是裸的邮件地址。
作法如:
@from = %(男人装 <noreply@nanrenainvren.com>)

不幸的是总报错:
01/09/09 22:26:50 ERROR smtpserver: Error parsing sender address: 男人装 <noreply@nanrenainvren.com>: Invalid character in local-part (user account) at position 4

但是
@recipients = %(男人装 <noreply@nanrenainvren.com>)
就可以正确发出去。

太郁闷了,结果还找错方向了,还以为email服务器出了问题,把james的源码下载下来端详了半天。。。也没看出个一二三。

回头又仔细读了几篇英文文章,操蛋一点的是,这一切太迟了,已经是半夜了,庆幸点的是我终于解决了。

老外有云:
http://www.ruby-forum.com/topic/185075
引用
Francesco Canessa wrote:
> Hi Chris,
>
> the workaround solved the problem, thank you!
>
> Is there another way to display a name with the email address without
> using angle brackets ?
>
> Thanks!
>
> On Jul 31, 2:26�pm, Chris Schumann <rails-mailing-l...@andreas-s.net>

Display? Sure. Do anything you want.

But as of Rails 2.3.3, the from email address will get the angle
brackets added, so it can only contain the address.

Rails 2.3.4 is/was supposed to fix that, and includes tests so it will
be ensured in future versions.


又恰好在另一个老外的文章中,看到一个链接,原文找不到了,链接还留着。
http://github.com/rails/rails/commit/1d57ccbc6f80a506e5c3867976793310e9148f03

被rails 2.3.3整懵了的是下面的代码:
actionmailer/lib/action_mailer/base.rb
-        sender = (mail['return-path'] && mail['return-path'].spec) || mail.from
+        sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']


加号那个是2.3.3后变的,减号那个是以前的。

于是,赶紧把actionmailer/lib/action_mailer/base.rb文件揪出,把mail['from'] 成成mail.from,重启服务器,发邮件吧!!!
"男人装"作为“发件人”的邮件终于出现在邮件列表里了。


注:以上男人装是假的,只是好玩。


---------我说JE,你就不能把广告上面打个空白行吗?----------
分享到:
评论
8 楼 Hooopo 2009-09-08  
我只管发邮件。。。。。。。。。
7 楼 Hooopo 2009-09-08  
不知道啊,,服务器是公司的。。。我不清楚
6 楼 netfork 2009-09-08  
Hooopo 写道
显示的是xxx啊!!!


不是吧,难道我的邮件服务器的事?
我用的是 james, 皮兄用的是什么?
5 楼 Hooopo 2009-09-08  
sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']
4 楼 Hooopo 2009-09-08  
除了会被一些gmail扔进垃圾邮件里面其他一切正常
3 楼 Hooopo 2009-09-08  
显示的是xxx啊!!!
2 楼 netfork 2009-09-08  
虎皮兄,你看看收到邮件中,发件人能显示为“xxx”吗?还是显示为“service”或“service@xxx.com”?

实际上,我debug的结果是,到了哪一步之后,xxx就被弄没了,好象只剩下<service@xxx.com>了。

另外,你看一下你的actionmailer/lib/action_mailer/base.rb文件,是不是下面一句话:
sender = (mail['return-path'] && mail['return-path'].spec) || mail['from'] 
1 楼 Hooopo 2009-09-08  
网叉兄,你说的问题我怎么没遇到啊?我是用2.3.3

def setup_email(user)

    recipients "#{user.email}"
    @from =    "xxx<service@xxx.com>"
    subject    ""
    body       ""
    sent_on    Time.now
    
  end

相关推荐

Global site tag (gtag.js) - Google Analytics