Search code examples
ruby-on-railsrubyemailemail-headers

custom email header


i want to add a enquiry id number to my emails so that when a user replies i i can automatically attach the email to an enquiry.

I am going to put a message with please do not remove this enquiry number when replying but it would be good if i can put a custom header with the enquiry number so the user doesnt see it.

Is this possible and is there any spam isssues addingh a custom header ?

best regards rick


Solution

  • Easy to do, just use the headers method from your ActionMailer subclass

    Per the email spec, start your non-standard headers with an X-

    Eg X-enquiry-num, not enquiry-num

    Also, don't count on the header not being stripped at some point in the mail transport/delivery/reply process. They usually get through, but not always.

    Another way to do it: add you enquiry number to your From and Reply-To addresses. Use the + sign so the main part of the address will be valid. Eg Reply-To: [email protected]

    -- A valid email address of [email protected] can have a + added and the mail will still be delivered to the same mailbox. Eg the same mailbox is used for [email protected], [email protected], [email protected]

    Your sw that automatically reads and handles the incoming mail can view the complete To address and handle appropriately.

    This technique is often used for automatically handling bounce messages send to a mailing list--emails are sent individually to everyone on the list with the person_id included as part of the reply-to and from addresses. That way the mailing list sw can automatically figure out which addresses bounced.