Condividi tramite


Alert emails not recognized by Outlook as "Alert Emails"

Recently a customer was following the KB 948321 and customizing the Alert notification emails being sent. He was just modifying the HTML part of it and rest using the same code. But when the emails were being received in the Outlook, they were not being recognized as Alert emails.

A regular alert email from SharePoint would look like this:

image

And would have the "Bell" icon and the email as such would have "Create Rule" button at the top.

image

But if you copy the exact code from the KB 948321, the email sent would look just like a normal email sent from a user.

Why does this happen?

Digging through the emails sent using the custom IAlertNotificationHandler and the emails sent by out-of-box SharePoint alerts, found that SharePoint adds a few headers to the email message like:

  • X-AlertTitle
  • X-AlertId
  • X-AlertWebUrl
  • X-AlertServerType
  • X-AlertWebSoap
  • X-Mailer

Debugging the custom IAlertNotificationHandler code, found that these headers are being set in SPAlertHandlerParams.headers collection. But in the sample code given, only "To" header is being pushed on to the SPUtility.SendEmail method.

SPUtility.SendEmail(web, true, false, ahp.headers["to"].ToString(), subject, build);

Set a break point and did a quick watch on ahp.headers and found:

image

So everything is already there in the headers, then why to pass just 1 header value to the SendEmail method. Checked the over loaded methods and found 1 which allows you to send the full collection of headers and replaced my code with:

 SPUtility.SendEmail(web, ahp.headers, build); 

Now the alert email was being displayed as expected and fully connected with SharePoint list happy

Comments

  • Anonymous
    May 12, 2009
    Recently while working with a customer, got a requirement which got me digging into the emails generated