views:

258

answers:

4

I am writing a rails application that sends emails when certain actions occur, users can then reply to these emails and the system needs to match the reply email to the original email sent to the user.

It seems like the best way to do this is to save the message id header field when sending messages, is this possible in ActionMailer? I can then retrieve the references header from replies and match the messages.

If this is not possible are there any alternate solutions?

+1  A: 

I'm not sure if it is possible within actionmailer to access the message id, however it is possible to add your own custom headers and then reference these when the user replies.

You do this within the mailer model as follows :-

@headers["VetId"] = order.vet_id
Steve Weet
+2  A: 

another alternative is to add a tracking code to the email's 'reply to' field something like this: reply to: notification+${notifcation_id}@yourdomain.com

for example, if the notification id is 123, the user will reply to [email protected], when the system receives the email, 123 can be used to identify the original message.

ez
A: 

Have a look on http://tmail.rubyforge.org/!

anka
That is not at all helpful.
Greg
Sorry Greg, what I wanted to mention is, that you can access the message id of your TMail::Mail object within your ActionMailer subclass. You cann see the reference at http://tmail.rubyforge.org/rdoc/classes/TMail/Mail.html#M000083 For instance you can create a new mail with "mail = UserMailer.create_notification_mail" (if UserMailer is your subclass of ActionMailer) and then access the message id with mail.message_id. But on the other side, I prefer the way "ez" descriebed above to add a token to your reply adress. Hope that helped a little bit more.
anka
A: 

With Rails 3, this is possible:

message = Mailer.welcome(@user).deliver
message.message_id #=> 4ccc56d19...

mattwindwer