标题:获取电子邮件名称/地址

发布于 2025-01-18 12:04:41 字数 638 浏览 2 评论 0原文

场景是我正在回复原始电子邮件。

我正在填充一条要发送的新邮件,其中包含原始邮件的所需元素(原始正文、收件人、发件人、回复等)。

在我的代码中,var headers 是原始电子邮件标题的集合。

newMessage 是一个新的 MimeMessage。

这是 headers[HeaderId.ReplyTo] 的值。 (来自原始电子邮件的标题。):

     "\"Sam Taylor\" <[email protected]>"

所以这是我填充新电子邮件消息的方法:

newMessage.To.Add(new MailboxAddress(headers[HeaderId.ReplyTo], "emailUser3"))

困扰我的是:我无法摆脱使用文字值“emailUser3”

如何在标题中找到该值“emailUser3”,以便我可以使用它来替换文字字符串?

谢谢。

Scenario is that I am replying to an original email message.

I am populating a new message to send with the required elements of the original message (the original body, reciepient, sender, the reply, etc.)

In my code, var headers is a collection the original email's headers.

newMessage is a new MimeMessage.

Here is what the value of headers[HeaderId.ReplyTo] is. (From the original email's headers.):

     "\"Sam Taylor\" <[email protected]>"

So here is what I do to populate the new email message TO:

newMessage.To.Add(new MailboxAddress(headers[HeaderId.ReplyTo], "emailUser3"))

What is bugging me: I cannot get away from using the literal value "emailUser3"

How can I find that value "emailUser3" in the headers so I can use that to replace the literal string?

Thank you.

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

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

发布评论

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

评论(1

入画浅相思 2025-01-25 12:04:41

首先,回复到标题包含地址的列表(在您的情况下仅是一个地址)。

其次,您需要解析标题值 - 不仅将整个值用作新的MailboxAddress的“名称”属性。

这是这样做的方法:

var replyToValue = headers[HeaderId.ReplyTo];
var replyToAddresses = InternetAddressList.Parse (replyToValue);

newMessage.To.AddRange (replyToAddresses);

First, The Reply-To header contains a list of addresses (which in your case is only a single address).

Second, you need to parse the header value - not just use the whole value as the "Name" property of a new MailboxAddress.

Here's how to do it:

var replyToValue = headers[HeaderId.ReplyTo];
var replyToAddresses = InternetAddressList.Parse (replyToValue);

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