Send email using SPUtility in SharePoint 2010

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.

More Blogs

Contact us

To begin your digital transformation, get in touch.

We’re pleased to address any inquiries you might have and assist you in selecting the service that best suits your requirements.

Your benefits:
Speak To Us