通过 SMTP 发送带有保证 ID 的消息

发布于 2024-10-15 19:45:01 字数 177 浏览 10 评论 0原文

美好的一天!
抱歉提出这么“明确”的问题,让我解释一下。在我的“程序”中,我通过(例如)gmail SMTP 服务器发送一些电子邮件。假设我发送的每封电子邮件的标头中都包含一些唯一的 ID(由我生成)。从 gmail 检索消息(例如,使用 python imaplib)后,我是否有机会再次获得该唯一 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾兮 2024-10-22 19:45:01

一般来说,MTA 将保留您引入的任何邮件标头。 需要中继 MTA 来执行此操作:

正如第 6.4 节中所讨论的,中继 SMTP 不需要检查或
对消息数据的标头部分或正文进行操作,并且不得
这样做除了添加自己的“Received:”头字段(第 4.4 节)
并且,可选地,尝试检测邮件系统中的循环(请参阅
第 6.3 节)。当然,该禁令也适用于任何
修改这些标题字段或文本(另请参见第 7.9 节)。

通常,接收 MTA 还将添加与邮件接收、垃圾邮件检查、循环检测等相关的其他标头。所以,是的,无论您使用哪个目标 SMTP 服务器(GMail 或其他),您几乎肯定是安全的。

如果 ID 确实是唯一的,您可能需要考虑将它们用作 您的 Message-ID 标头值。为此目的使用 Message-ID 的好处是,当用户回复您的消息时,他们通常会在其 In-Reply 中包含该 Message-ID 值-To 和/或 References 标头:

“消息 ID:”字段提供唯一的消息标识符,
指特定消息的特定版本。这
消息标识符的唯一性由主机保证
生成它(见下文)。该消息标识符的目的是
机器可读,但对人类不一定有意义。一条消息
标识符恰好属于特定消息的一个版本;
对消息的后续修订每次都会收到新消息
标识符。

创建回复时使用“回复:”和“参考:”字段
回复消息。它们保存原始消息的标识符
消息和其他消息的消息标识符(例如,
如果回复消息本身就是回复)。这
“In-Reply-To:”字段可用于标识消息(或
消息),新消息是其回复,而
“References:”字段可用于标识“线程”
对话。

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.

娇纵 2024-10-22 19:45:01

我刚刚对此做了一些测试,看起来可行,而且实际上非常简单。

我使用 Mail.php 扩展来实现这一点(不过应该没关系)。我在发送消息之前添加了一个额外的标头(“Trevor”=>“我的测试”)。我在 Gmail 中收到了该邮件并执行了“显示原始内容”,它包含标题。

然后我拉下这条消息(也通过 PHP),标题包含我输入的自定义行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文