send message through SMTP with guarantee ID

牧云@^-^@ 提交于 2020-01-04 06:09:26

问题


good day!
sorry for so "clear" question, let me explain. In my "program", i'm sending some emails, through (for example) gmail SMTP server. Let's pretend that every email, which i've sent, contains some unique ID (generated by me) in header. Is there any chance, after retrieving that messages from gmail (for example, with python imaplib), i will get that unique ID (in header) again?
thanks


回答1:


In general, MTAs will preserve whatever message headers you introduce. Relaying MTAs are required to do so:

As discussed in Section 6.4, a relay SMTP has no need to inspect or act upon the header section or body of the message data and MUST NOT do so except to add its own "Received:" header field (Section 4.4) and, optionally, to attempt to detect looping in the mail system (see Section 6.3). Of course, this prohibition also applies to any modifications of these header fields or text (see also Section 7.9).

And in general the receiving MTA will also just add further headers related to message receipt, spam checking, loop detection, and the like. So yes, you're almost certainly going to be safe regardless of which destination SMTP server you use, GMail or otherwise.

If the IDs truly are unique, you may want to consider using them as part of your Message-ID header value. The benefit of using Message-ID for this purpose is that when users reply to your message, they will generally include that Message-ID value in their In-Reply-To and/or References header:

The "Message-ID:" field provides a unique message identifier that refers to a particular version of a particular message. The uniqueness of the message identifier is guaranteed by the host that generates it (see below). This message identifier is intended to be machine readable and not necessarily meaningful to humans. A message identifier pertains to exactly one version of a particular message; subsequent revisions to the message each receive new message identifiers.

The "In-Reply-To:" and "References:" fields are used when creating a reply to a message. They hold the message identifier of the original message and the message identifiers of other messages (for example, in the case of a reply to a message that was itself a reply). The "In-Reply-To:" field may be used to identify the message (or messages) to which the new message is a reply, while the "References:" field may be used to identify a "thread" of conversation.




回答2:


I just did a little testing on this, and it looks possible and actually pretty easy.

I used the Mail.php extension to make this happen (shouldn't matter, though). I added an extra header before I sent the message ("Trevor" => "My Test"). I received the message in Gmail and did a "Show Original" and it contains the header.

I then pulled this message down (also via PHP) and the header contains the custom line I entered.



来源:https://stackoverflow.com/questions/4875067/send-message-through-smtp-with-guarantee-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!