简体   繁体   English

我可以使用System.Net.Mail将电子邮件标记为Outlook的“高重要性”吗?

[英]Can I mark an Email as “High Importance” for Outlook using System.Net.Mail?

Part of the application I'm working on for my client involves sending emails for events. 我正在为客户处理的应用程序的一部分涉及发送事件电子邮件。 Sometimes these are highly important. 有时这些非常重要。 My client, and most of my client's clients, use Outlook, which has the ability to mark a mail message as High Importance. 我的客户以及我大多数客户的客户都使用Outlook,它可以将邮件标记为高度重要。

Now, I know it is callous to assume that all end users will be using the same interface, sp I am not. 现在,我知道假设所有最终用户都将使用相同的界面是可笑的,但我不是。 But considering you can send email from Outlook as High Importance even if the target is not necessarily reading through Outlook, that means that there is basically some data stored, somehow, that lets Outlook know if a particular message was assigned as High Importance. 但是考虑到即使目标不一定通过Outlook读取,也可以将Outlook作为高度重要性发送电子邮件,这意味着基本上已经存储了一些数据,以某种方式使Outlook知道特定邮件是否被指定为高度重要性。 That's my interpretation, at least. 至少那是我的解释。

The application currently uses System.Net.Mail to send out emails, using System.Net.Mail.MailMessages for writing them and System.Net.Mail.SmtpClient to send them. 该应用目前使用System.Net.Mail来发送电子邮件,使用System.Net.Mail.MailMessages用于编写和System.Net.Mail.SmtpClient给他们。 Is it possible to set this "High Importance" setting with System.Net.Mail 's abilities? 是否可以使用System.Net.Mail的功能设置此“高重要性”设置? If not, is there any assembly available which can configure this setting? 如果不是,是否有可用于配置此设置的程序集?

You can set the System.Net.Mail.MailPriority setting. 您可以设置System.Net.Mail.MailPriority设置。

MailPriority.High for example. 例如MailPriority.High

Set the Priority property of the mail message. 设置邮件的优先级属性。 Its values are Normal, Low or High. 其值为“正常”,“低”或“高”。

Very late edit: As @StefanSteiger notes, Priority is only guaranteed to work for Outlook. 很晚的编辑:如@StefanSteiger所述,仅保证优先级可用于Outlook。 In the intervening 8 years since this question/answer were posted, the industry has settled on the Importance header as the preferred way to do this. 自发布问题/答案以来的8年间,该行业将“重要性”标头确定为首选的方式。

Even later edit: The source for MailMessage makes it clear that setting the Priority actually sets three things: the XPriority header, the Priority header, and the Importance header . 甚至以后进行编辑: MailMessage源代码清楚地表明,设置Priority实际上设置了三件事:XPriority标头,Priority标头和Importance标头 So using the Priority property will behave as expected in any mail client, and will set the appropriate headers. 因此,使用Priority属性将在任何邮件客户端中按预期方式工作,并将设置适当的标头。

Use this - it works for me. 使用它-对我有用。

Dim mail As New MailMessage()
mail = New MailMessage()
mail.Priority = MailPriority.High
mail.Priority = MailPriority.Normal
mail.Priority = MailPriority.Low

Just because Outlook treats priority as importance, that doesn't mean all other email programs do so as well. 仅仅因为Outlook将优先级视为重要,并不意味着所有其他电子邮件程序也都将优先级视为重要。

Priority and importance are NOT the same thing. 优先和重要性不是一回事。

The correct answer is: 正确的答案是:

mail.Headers.Add("Importance", "High"); // High, normal, or low

values are case insensitive. 值不区分大小写。

https://www.iana.org/assignments/message-headers/message-headers.xhtml https://www.iana.org/assignments/message-headers/message-headers.xhtml
https://tools.ietf.org/html/rfc4021#page-32 https://tools.ietf.org/html/rfc4021#page-32

Jumping in late here! 在这里跳得晚! Priority and Importance are not the same, but both are available to most developers to set. 优先级和重要性并不相同,但是大多数开发人员都可以设置两者。 How do you choose? 您如何选择? Well, Priority is defined in RFC 4021, 2.1.54, as a property that affects transmission speed and delivery ("normal", "urgent", and "non-urgent"). 好吧,优先级在RFC 4021 2.1.54中定义为影响传输速度和传输的属性(“正常”,“紧急”和“非紧急”)。 Importance is defined in RFC 4021, 2.1.52, as a property that is a hint from the originator to the recipients about how important a message is ("high", "normal", and "low"). 重要性在RFC 4021,2.1.52中定义为一种属性,它是从始发者到收件人的提示,即消息的重要性(“高”,“正常”和“低”)。

For my use case, I'm targeting Outlook users and using MimeKit to build the emails. 对于我的用例,我以Outlook用户为目标,并使用MimeKit生成电子邮件。 Importance is what most email clients care about, so here's what my code might look like: 大多数电子邮件客户关心的是重要性,因此,我的代码可能如下所示:

using MimeKit;
var message = new MimeMessage();
message.Importance = MessageImportance.High;

I'll repost Steiger's links, because he's spot-on: 我将重新张贴Steiger的链接,因为他在现场:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM