Can I mark an Email as "High Importance" for Outlook using System.Net.Mail?
Asked Answered
C

5

24

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.

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. 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. Is it possible to set this "High Importance" setting with System.Net.Mail's abilities? If not, is there any assembly available which can configure this setting?

Chivalric answered 22/4, 2010 at 17:8 Comment(1)
When you create the MailMessage, set message.Priority = MailPriority.High; example: aspnettutorials.com/tutorials/email/…Glabella
N
30

Set the Priority property of the mail message. Its values are Normal, Low or High.

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.

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.

Nidia answered 22/4, 2010 at 17:10 Comment(4)
Priority and Importance are NOT the same thing. They both exist on Mail.Rebekahrebekkah
@StefanSteiger Importance is not documented as a property on MailMessage, nor does it appear as an available property in Intellisense. It is documented as an available header, but no other information is given. And again, this answer is 8 years old so the state of the framework classes could easily have changed in the meantime.Nidia
The correct answer is: mail.Headers.Add("Importance", "High"); // High, normal, or low - case insensitive.Rebekahrebekkah
@StefanSteiger Again, this is an 8-year old question/answer. You're judging it based on something that did not even exist for another 5 years after it was written.Nidia
S
23

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

MailPriority.High for example.

Stat answered 22/4, 2010 at 17:9 Comment(0)
S
13

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
Selassie answered 13/7, 2013 at 5:26 Comment(0)
R
5

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://www.rfc-editor.org/rfc/rfc4021#page-32

Rebekahrebekkah answered 14/9, 2018 at 8:58 Comment(0)
C
0

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:

Cleruchy answered 6/12, 2018 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.