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

今天想实现发邮件时,接收到的邮件是显示发件人的名,而不是裸的邮件地址。
作法如:
@from = %(男人装 <[email protected]>)

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

但是
@recipients = %(男人装 <[email protected]>)
就可以正确发出去。

太郁闷了,结果还找错方向了,还以为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 <[email protected]>

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,你就不能把广告上面打个空白行吗?----------

你可能感兴趣的:(Ruby,Rails,Gmail)