Thursday, 20 December 2012

Programmatically sending mail in SharePoint using SPUtility class


To send mails using SharePoint API, we can use SPUtility class sendMail method. For referencehttp://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.

2 comments:

  1. This certification is meant to test a person's knowledge of SharePoint 2010 application development but it's also a good way to learn about SharePoint 2010 development.

    For More Info :- Sharepoint 2010 Developers

    Thanks.

    ReplyDelete