Search This Blog

Thursday, May 12, 2011

SharePoint is configure to send the mail.

Sending the Mail


Below code will explain you how you can send the mail using SharePoint configuration.

This code is uses classes form the Microsoft.SharePoint.dll and Microsoft.SharePoint.Utilities.dll.

public bool SendMail()
{
//Get Current website
SPWeb web = SPContext.Current.Web;

//Check emilServer is set
bool isEmailServerSet = SPUtility.IsEmailServerSet(web);

bool result = false;
if (isEmailServerSet)
{
//The email header
StringDictionary headers = new StringDictionary();
headers.Add("to","chiragbrajput@hotmail.com"));
headers.Add("cc", Chiragbrajput@hotmail.com);


//Change the from setting(optional)
headers.Add("from","hotmailAdmin@hotmail.com");
headers.Add("subject", "TestingEmail");
headers.Add("content-type", "text/html"); //This is the default type, so isn’t neccessary.

//The email body
string bodyText = "hello World";
//indicate mail send succefully or not.
result = SPUtility.SendEmail(web, headers, bodyText);
}
}