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

后端 未结 5 1867
感情败类
感情败类 2021-01-03 20:36

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,

相关标签:
5条回答
  • 2021-01-03 21:05

    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
    
    0 讨论(0)
  • 2021-01-03 21:11

    Just because Outlook treats priority as importance, that doesn't mean all other email programs do so as well.

    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://tools.ietf.org/html/rfc4021#page-32

    0 讨论(0)
  • 2021-01-03 21:12

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

    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. So using the Priority property will behave as expected in any mail client, and will set the appropriate headers.

    0 讨论(0)
  • 2021-01-03 21:17

    You can set the System.Net.Mail.MailPriority setting.

    MailPriority.High for example.

    0 讨论(0)
  • 2021-01-03 21:29

    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"). 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").

    For my use case, I'm targeting Outlook users and using MimeKit to build the emails. 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:

    • https://www.iana.org/assignments/message-headers/message-headers.xhtml
    • https://tools.ietf.org/html/rfc4021#page-32
    0 讨论(0)
提交回复
热议问题