Sending Emails in Sharepoint

Sending Emails in Sharepoint

What is the good practice for sending emails from my sharepoint webparts and/or customized features /or through code.

You can  use the normal Smtp Client Class of System.Net.Mail namespace  to send email or use the built in Utilities (Microsoft.SharePoint.Utilities.SPUtility )


SharePoint SPUtility class has SendEmail() method  to send email to any email address. By default, SPUtility.SendEmail() method take the ‘From address’ from Outgoing E-Mail Settings in Central administration. If it is not set , you can use SPUtility.IsEmailServerSet method to check if server is configured with SMTP mail settings or not.

SPUtility.SendEmail() method which by default picks the ‘From address’ from Central administartion-> Operations-> Outgoing E-Mail Settings.

using Microsoft.SharePoint.Utilities;
SPUtility.SendEmail(SPContext.Current.Web, false, false,
     "", "subject",

SPUtility sendemail method has some limitations like:
  • It don’t Provide support for attachments
  • The from address will be the “Outbound Sender Address” configured in the Central administration .
  • Message body should not exceed 2048 characters.

If you want to send mail with attachment and long mail, use the System.Net.Mail class methods


in both case normal Smtp Client Class of System.Net.Mail namespace  to send email or use the built in Utilities (Microsoft.SharePoint.Utilities.SPUtility ) , we need to configure Web Application Outgoing E-Mail Settings for that particular Web Application in which your site is hosted in Central Administration

send mail by Sharepoint Server

Send mail by Sharepoint Server



send mail by  Microsoft.SharePoint.Utilities.SPUtility 
 using (SPSite objSPSite = new SPSite(objSPSiteId))
                using (objSPWeb = objSPSite.AllWebs[properties.OpenWeb().ID])
                    bool Mailresult = SPUtility.SendEmail(objSPWeb, true, true, "", "test Mail.", "Tech Content");

In some cases, you may need to run this code with elevated privileges:

bool Mailresult= SPUtility.SendEmail(objSPWeb, true, true, “”, “test Mail.”, “Tech Content”);


SendEmail method returns a boolean, indicating if sending the email was successful or not.



send mail by   SmtpClient Class of System.Net.Mail namespace 

   using (SPSite objSPSite = new SPSite(objSPSiteId))
                using (objSPWeb = objSPSite.AllWebs[properties.OpenWeb().ID])
                    string smtpServer = objSPSite.WebApplication.OutboundMailServiceInstance.Server.Address;
                    string smtpFrom = objSPSite.WebApplication.OutboundMailSenderAddress;
                    MailMessage mailMessage = new MailMessage(smtpFrom, "");
                    mailMessage.Body = "Test Body";
                    mailMessage.Subject = "Test Subject";
                    SmtpClient objSmtpClient = new SmtpClient();

We need put  these entry in web.config :


<smtp from=””>
<network host=”localhost”/>.

Note: while on event receiver to send the mail by SPUtility class, you may get some issue, event receiver runs in the context of an HTTP request. It is known that SPUtility.SendEmail has issues with this. A common solution is to set HttpContext.Current to null while sending the email:

HttpContext.Current = null;
SPUtility.SendEmail(currt.Web, headers, bodyText.ToString());

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 9 =

All Rights Reserved 2019 | DesignzRush (OPC) Pvt. Ltd.