Search code examples
emailsmtpemail-headers

send message through SMTP with guarantee ID


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


Solution

  • 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.