About Me

I am a Software Engineer presently working in Microsoft as vendor.The main aim of this blog is to Share my knowledge in Sharepoint,AZURE and Silverlight.

Sunday, 27 July 2008

Sending Mail in Sharepoint using code.

we should include the following namespace
for this Add reference of Microsoft.Sharepoint in references.

using Microsoft.SharePoint.Utilities;

Get the header information which contains To,Subject,CC...

System.Collections.Specialized.StringDictionary headers = new System.Collections.Specialized.StringDictionary();
headers["To"] = v-sasikp@microsoft.com;
headers["Subject"] = "This is test mail";


finally,
SPUtility.SendEmail(myweb, headers, emailMsg, false);

But this requires configuration of email server in central administration.

Simple Ex:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace blogmail
{
class Program
{
static void Main(string[] args)
{
SPSite Site = new SPSite("http://sasikp-v:4008/");
SPWeb myweb = Site.OpenWeb();
SPUtility.SendEmail(myweb, false, false,"v-sasikp@microsoft.com", "This is test mail for blog","Pls dont reply to this mail this is testmail. ", false);

}
}
}

No comments: