标题:获取电子邮件名称/地址
场景是我正在回复原始电子邮件。
我正在填充一条要发送的新邮件,其中包含原始邮件的所需元素(原始正文、收件人、发件人、回复等)。
在我的代码中,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,回复到标题包含地址的列表(在您的情况下仅是一个地址)。
其次,您需要解析标题值 - 不仅将整个值用作新的MailboxAddress的“名称”属性。
这是这样做的方法:
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: