High priority emails

There are several different email headers that make email high priority.

Most correct is Priority header, but also Importance is used.
Outlook uses X-Priority header.

Mail.dll email library offers simple solution of this problem: PriorityHigh() method.

The following code sends high priority email, that has all mentioned above headers set accordingly:

// C# version:
MailBuilder builder = new MailBuilder();
builder.Subject = "This is important";
builder.Html = "<html>....</html>";
builder.From.Add(new MailBox("alice@mail.com", "Alice"));
builder.To.Add(new MailBox("bob@mail.com", "Bob"));

builder.PriorityHigh();

IMail email = builder.Create();

using (Smtp client = new Smtp())
{
    client.ConnectSSL("smtp.example.org");
    client.UseBestLogin("alice@example.org", "password");
    client.SendMessage(email);
    client.Close();
}

and as usual VB.NET code:

' VB.NET version:

Dim builder As MailBuilder = New MailBuilder()
builder.Subject = "This is important"
builder.Html = "<html>....</html>"
builder.From.Add(New MailBox("alice@mail.com", "Alice"))
builder.[To].Add(New MailBox("bob@mail.com", "Bob"))

builder.PriorityHigh()

Dim email As IMail = builder.Create()

Using client As Smtp = New Smtp()
    client.ConnectSSL("smtp.example.org")
    client.UseBestLogin("alice@example.org", "password")
    client.SendMessage(email)
    client.Close()
End Using

Using fluent interface:

// C# version:

using Fluent = Limilabs.Mail.Fluent;

Fluent.Mail.Html("<html>....</html>")
    .Subject("This is important")
    .To("to@example.com")
    .From("from@example.com")
    .PriorityHigh()
    .UsingNewSmtp()
    .Server("smtp.example.com")
    .WithCredentials("user", "password")
    .WithSSL()
    .Send();
' VB.NET version:

Imports Fluent = Limilabs.Mail.Fluent;

Fluent.Mail.Html("<html>....</html>") _
    .Subject("This is important") _
    .To("to@example.com") _
    .From("from@example.com") _
    .PriorityHigh() _
    .UsingNewSmtp() _
    .Server("smtp.example.com") _
    .WithCredentials("user", "password") _
    .WithSSL() _
    .Send()

PriorityLow() method is also available.

It’s also really easy to check the email’s priority with GetGenericPriority.
GetGenericPriority checks Priority, Importance and X-Priority headers.

// C# version:

IMail email = new MailBuilder()
    .CreateFromEml(imap.GetMessageByUID(uid))

GenericPriority priority = email.GetGenericPriority();
if (priority == GenericPriority.High)
{
    // Your code goes here
}

' VB.NET version:

Dim email As IMail = New MailBuilder() _
    .CreateFromEml(imap.GetMessageByUID(uid))

Dim priority As GenericPriority = email.GetGenericPriority()

If priority = GenericPriority.High Then
    ' Your code goes here
End If

Tags: , , ,

Questions?

Consider using our Q&A forum for asking any questions.