开发者

Trying to set the message-id, in-reply-to, etc... in ActionMailer

I'm working on an app that needs to be able to send out email updates and then route the reply back to the original item.

All emails will come to a 开发者_Python百科single address (this can't change unfortunately), and I need to be able to determine where they go. My initial thought was setting the message-id for the item so that it comes back as a References header.

any ideas on how to accomplish this with ActionMailer?


FINALLY found it.

First the problem: ActionMailer calls on the ready_to_send function inside TMail when sending using smtp, which in-turn calls the add_message_id function which overrides anything you put there.

Solution: there's an undocumented (as far as I can tell) method in TMail called enforced_message_id=(val). using this INSTEAD of message_id ensures that add_message_id won't overwrite your values. For example, you could:

mail = MyMailer.create_mail_function(values)
mail.enforced_message_id = '<my_not_proper_message_id>'
MyMailer.deliver(mail)

You need to be careful with this, because message_id's can be tricky. They must be unique and valid. I assume there's a reason TMail made it a bit of a pain to override the default.

Hopefully this saves someone a wasted afternoon (speaking from experience here ;-)


Note that enforced_message_id is only for TMail >= 1.2.7 (shipped with Rails >= 2.3.6). The function does not exist for Tmail <= 1.2.3 (for Rails <= 2.3.5). A workaround for Rails 2.3.6 is to change net.rb's add_message_id to the following:

def add_message_id( fqdn = nil )
  self.message_id = ::TMail::new_message_id(fqdn) if self.message_id.nil?
end

That's the "vendor" copy of TMail in ActionMailer in your Rails installation. (Find the root of the Rails installation using "gem environment").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜