Monday, March 2, 2009

Auto Generated email for Sharepoint Workflow -C#.net

Method used for sending email is in “Microsoft।SharePoint।Utilities” This helps you to send email through sharepoint web application, custom workflow using C#.net

The SPUtility.SendEmail method enables you to send an email from the context of a SharePoint Web (SPWeb) object. The SMTP settings associated with the SPWeb object are used to send the email. The method returns a boolean value that represents whether the email was sent successfully.

SPUtility.SendEmail Method (Microsoft.SharePoint.Utilities)
SPUtility.SendEmail (SPWeb, Boolean, Boolean, String, String, String)
example:

try
{
SPWeb thisWeb = SPControl.GetContextWeb(Context);
string toField = "mailaddress@microsoft.com";
string subject = "Test Message";
string body = "Message sent from SharePoint";
bool success = SPUtility.SendEmail(thisWeb,true, true, toField, subject, body);
}
catch (Exception ex)
{
// handle exception
}

3 comments:

Bissell said...

Is there any way to put this into a workflow generated with SPD? Where should this code snipet be placed?

Amila Abeyrathne said...

I have used this in custom workflows in visual studio not in SPD. sorry i haven't used that in SPD.

Unknown said...

how do you send an email using custom workflow, genereated in visual studio to send email to a sharepoint group?