custom email header

两盒软妹~` 提交于 2019-12-04 19:27:55

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: cust_svc+123@mycompany.com

-- A valid email address of foo@woof.com can have a + added and the mail will still be delivered to the same mailbox. Eg the same mailbox is used for foo@woof.com, foo+123@woof.com, foo+123_456@woof.com

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.

There are already standard headers In-Reply-To: and References: as listed in RFC-2076 "Common Internet Message Headers" that may do what you want. Both date back to RFC-822

These headers reference the Message-ID header.

You could use the message id. I've just starting using this in the format

<large_random_number+enquiry_id@domain_name.com>

and it seems to be returned consistently.

EG:

Content-Type:   multipart/alternative; boundary="------------070002000603000906000608"
Date:   Sat, 10 Nov 2012 17:23:48 +0100 [17:23:48 CET]
Delivery-date:  Sat, 10 Nov 2012 17:23:48 +0100
Envelope-to:    admin@some_domain.co.uk
From:   ChrisB <chrisb@example.com>
In-Reply-To:    <edIJcHTHHJUqC0LgtFkLBc8yNY6wypOkJgCoIXLSUuQ+12-0152@some_domain.co.uk>
MIME-Version:   1.0
Message-ID:     <509E7F94.4050304@example.com>
Received:   
References:     <edIJcHTHHJUqC0LgtFkLBc8yNY6wypOkJgCoIXLSUuQ+12-0152@some_domain.co.uk>
Return-path:    <chrisb@example.com>
Subject:    Re: BOOKING FORM
To:     <admin@some_domain.co.uk>
User-Agent:     Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 
Thunderbird/16.0.2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!