Send email using SPUtility in SharePoint 2010
17 March 2011
Sending email is a key function of enterprises solutions. Inside SharePoint collaboration environment you always need to send email from within SharePoint. For this purpose you can use SPUtility class SendEmail method.
Below is a simple example code for sending email using SPUtility.
Add namespace reference:
Microsoft.SharePoint.Utilities //Code: private viod SendEmail() { try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID, SPContext.Current.Site.Zone)) { using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) { SPUtility.SendEmail(web, true, true, "[email protected]", "Subject", "Your message body will go here"); } } }); } catch (Exception ex) {} }
As you can see that sending email using SPUtility is straightforward, please also note the following considerations
1. No attachment allowed
2. Message body size cannot exceed 2048 characters.
3. The form address will be the “Outbound Sender Address” configured in the central admin.