in Development

E-Mail Alerts

I’m sure that all of us first or later needed to write a piece of code that sends alerts by e-mail, it doesn’t matter if it was a very complex notification system or if we just wrote a few lines to do it, but probably all of us did it. If people use Outlook, there is a very simple trick to stand out the e-mails you send and impress some end-users.

The only thing you need to do is to add a header to the instance of the MailMessage class and Outlook will show the mails with a bell icon instead of the standard envelope icon. Let’s see how to do it exactly.

   1: System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); 
   2:  
   3: message.From = "xxx"
   4: message.To = "xxx"
   5: message.Subject = "xxx"
   6: message.Body = "xxxx" 
   7:  
   8: message.Headers.Add("message-id", "<3BD50098E401463AA228377848493927-1>"); 
   9:  
  10: System.Web.Mail.SmtpMail.SmtpServer = "localhost"
  11: System.Web.Mail.SmtpMail.Send(message); 

The header we add is a formatted string with a fixed Guid and the real message id, in this case 1. The Guid “3BD50098E401463AA228377848493927” is what does the trick.

This happens because Outlook and actually any application compatible with Sharepoint Services thinks that the message received is an alert coming from Sharepoint Services so it identifies them in showing a bell as the message icon.

I just talk about this as a funny thing in order your notification applications seem more sophisticated, but there are some interesting concepts behind it. Maybe you want to take a look to the SMTP Headers/X-Headers and the extensibility of the Sharepoint Services.

PS: Happy New Year!!!!