Friday, 1 June 2012

Programmatically sending mail in SharePoint using SPUtility class

To send mails using SharePoint API, we can use SPUtility class sendMail method. For reference http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx
To use this method we will require:

using Microsoft.SharePoint.Utilities;
using System.Collections.Specialized;

You can assign to, cc, bcc, from, subject by creating stringdictionary, like
StringDictionary headers = new StringDictionary();
headers.add("to",strTo);
headers.add("cc",strCC);
headers.add("bcc",strbcc);
headers.add("from",strFrom);
headers.add("subject",strSubject);
headers.add("content-type","text/html");


string emailBody = “Hi<br><br>Sending mails using SPUtility.”;

SPUtility.SendEmail(web, headers, emailBody);

Where web is SPWeb object that represents site from which you want to send mail.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...