Thursday, February 23, 2012

Sending emails from SharePoint using SPUtility

Method 1
--------
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
try
{
readEmailIDs();
StringDictionary headers = new StringDictionary();

headers.Add("to", strRecepients);
//headers.add("cc", "manager@test.com");
//headers.add("bcc", "user@test.com");
headers.Add("from", strFromAddress);

headers.Add("subject", strSubject);
headers.Add("content-type", "text/html");
bool success = SPUtility.SendEmail(web, headers, strEmailContent);

}
catch (Exception e)
{

}
}
}


Method 2:
----------

using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
try
{

string subject = strSubject;
string body = emailContent;
string subject = strSubject;
string body = "BodyText";
bool success = SPUtility.SendEmail(web, true, false, toField, strSubject, strEmailText);

}
catch (Exception e)
{

}
}
}

No comments:

Post a Comment