1

I want to set the mail priority using SPUtility.SendMail()

I know I can do it with

MailMessage myMail = new MailMessage();
myMail.From = "from@microsoft.com";
myMail.To = "to@microsoft.com";
myMail.Subject = "UtilMailMessage001";
myMail.Priority = MailPriority.Low;

But my data center folks want me to use SPUtility.SendMail(). Is it possbile to set the priority with SPUtility.SendMail()?

Robert Lindgren
  • 24,520
  • 12
  • 53
  • 79
mikemurf22
  • 267
  • 1
  • 4
  • 10

4 Answers4

5

I have not had an opportunity to try this, but there is a constructor of SPUtility.SendEmail which accepts a StringDictionary of MessageHeaders.

According to this link, these are the 3 headers Microsoft uses to create a high priority email.

X-Priority: 1 (Highest)
X-MSMail-Priority: High
Importance: High

So to use it with SPUtility.SendEmail, use this code to create the headers.

StringDictionary messageHeaders = new StringDictionary();
messageHeaders.Add("X-Priority", "1 (Highest)");
messageHeaders.Add("X-MSMail-Priority", "High");
messageHeaders.Add("Importance", "High");
Tim Gabrhel
  • 2,325
  • 2
  • 24
  • 46
  • for completness. I also added the folowing headers since they were no longer parameters messageHeader.Add("to", MySettings.Instance.ToAddress); messageHeader.Add("from", "sharepoint@test.com"); messageHeader.Add("subject", "subject"); messageHeader.Add("content-type", "text/html"); – mikemurf22 Sep 12 '11 at 21:02
0

Use this code

StringDictionary messageHeaders = new StringDictionary();
messageHeaders.Add("X-Priority", "1 (Highest)");
messageHeaders.Add("X-MSMail-Priority", "High");
messageHeaders.Add("Importance", "High");

with

 SPUtility.SendEmail(elevetedweb, headers, strMessage.ToString());

This sends email marked as high-priority

Robert Lindgren
  • 24,520
  • 12
  • 53
  • 79
0

No, there is nothing in the function to specify email priority. You would need to use the .NET mail functions that you mentioned in your post. See http://msdn.microsoft.com/en-us/library/ms463202.aspx for all the available options on that function.

John Chapman
  • 11,941
  • 6
  • 36
  • 62
0

Working solution in SharePoint CSOM

    using (ClientContext clientContext = new ClientContext(Constants.SPSiteURL))
{
   EmailProperties email = new EmailProperties();
   email.To = toEmail;
   email.Subject = String.Format(subject);
   email.Body = body;
   email.AdditionalHeaders = new Dictionary<string, string>() 
   {
       {"X-Priority", "1 (Highest)"},
       {"X-MSMail-Priority", "High"},
       {"Importance", "High"}
   };

   Utility.SendEmail(clientContext, email);
   clientContext.ExecuteQuery();
   flag = true;
}
Ishan
  • 774
  • 5
  • 19
  • 44