Automating email notifications is a fundamental requirement for most modern business applications. Whether you are building a custom workflow, a provider-hosted app, or a background service, knowing how to send email via SharePoint CSOM (Client Object Model) is a critical skill for any developer.

In this guide, you will learn multiple methods to send emails from SharePoint, ranging from the native CSOM Utility class to the REST API and standard SMTP methods. We will also address common permission hurdles that often stop developers in their tracks when trying to implement these solutions.

Understanding the SharePoint CSOM Utility Class

The most common way to send emails within the SharePoint ecosystem is by using the Microsoft.SharePoint.Client.Utilities.Utility class. This method is specifically designed to work within the SharePoint context, meaning it uses SharePoint's internal mail configuration to route messages.

When you use this approach, you are essentially asking SharePoint to handle the delivery. This is highly efficient for internal notifications because you don't need to manage SMTP credentials or server addresses manually. However, there is a significant limitation: by default, this method generally only supports sending emails to users who are already recognized within your SharePoint environment or your organization's Exchange directory.

Implementation Example in C

To use this method, you need to populate the EmailProperties object and pass it to the Utility.SendEmail method. Here is the standard implementation using C#:

private void SendEmail(ClientContext clientContext)
{
    // Ensure the recipient is a valid user in the site context
    User sendToUser = clientContext.Web.EnsureUser("[email protected]");
    clientContext.Load(sendToUser);
    clientContext.ExecuteQuery();

    // Retrieve the email address of the current user for context
    string email = Microsoft.SharePoint.Client.Utilities.Utility.GetCurrentUserEmailAddresses(clientContext).Value;

    // Configure email properties
    Microsoft.SharePoint.Client.Utilities.EmailProperties properties = new Microsoft.SharePoint.Client.Utilities.EmailProperties();
    properties.To = new string[] { sendToUser.Email };
    properties.Subject = "System Notification: Task Update";
    properties.Body = "This is an automated notification sent via SharePoint CSOM.";

    // Trigger the email sending process
    Microsoft.SharePoint.Client.Utilities.Utility.SendEmail(clientContext, properties);

    // Execute the query to finalize the request
    clientContext.ExecuteQuery();
}

Resolving Permission Issues

A frequent roadblock is the "Access Denied" error or permission exceptions. If you are running this within a SharePoint Add-in or a Provider-Hosted App, you must ensure your AppManifest.xml has the correct permissions.

Specifically, the application typically requires at least Web level permissions with Write or Full Control rights. Without these, the Utility.SendEmail method will fail because the service account or app identity lacks the authority to trigger the mail service on behalf of the site.

Sending Emails via the SharePoint REST API

If you are working in a client-side environment, such as a SharePoint Framework (SPFx) web part or a custom JavaScript application, the REST API is your best friend. The REST API endpoint /_api/SP.Utilities.Utility.SendEmail provides the same functionality as the CSOM utility but through a standard HTTP POST request.

This method is particularly useful for modern SharePoint development where C# might not be available. Below is an example using jQuery and AJAX to send an email:

var mail = {
    properties: {
        __metadata: { 'type': 'SP.Utilities.EmailProperties' },
        From: '[email protected]',
        To: { 'results': ['[email protected]','[email protected]'] },
        Body: 'This is the email body content.',
        Subject: 'Automated Alert'
    }
};

// Construct the URL for the app web or host web
var getAppWebUrlUrl = decodeURIComponent(utils.getQueryStringParameter("SPAppWebUrl").replace("#", ""));
var urlTemplate = getAppWebUrlUrl + "/_api/SP.Utilities.Utility.SendEmail";

$.ajax({
    contentType: 'application/json',
    url: urlTemplate,
    type: "POST",
    data: JSON.stringify(mail),
    headers: {
        "Accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {
        console.log("Email sent successfully!");
    },
    error: function (err) {
        console.error("Error sending email: " + JSON.stringify(err));
    }
});

Using Standard SMTP for External Recipients

While the SharePoint-native methods are convenient, they have two major drawbacks: they cannot easily send attachments and they often struggle with external recipients (users outside your M365 tenant).

If your requirements include sending PDF reports or reaching external vendors, using the standard .NET SmtpClient is the most reliable approach. This method bypasses SharePoint's internal utility and connects directly to an email server (like Gmail, Outlook.com, or your corporate SMTP relay).

MailMessage mail = new MailMessage("[email protected]", "[email protected]");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.office365.com"; // Or your specific SMTP host

mail.Subject = "External Project Update";
mail.Body = "Please find the details of the project attached.";

// You can also add attachments here
// mail.Attachments.Add(new Attachment("C:\\report.pdf"));

client.Send(mail);

Note: If you are using SharePoint Online, Microsoft has been deprecating Basic Authentication for SMTP. It is recommended to use the Microsoft Graph API for sending emails in modern M365 environments to ensure long-term compatibility and security.

Comparing the Methods

Feature SharePoint CSOM/REST Standard SMTP (.NET)
Ease of Setup High (Uses existing SP config) Medium (Requires SMTP server)
External Recipients Limited/Requires Config Full Support
Attachments Not Supported Supported
Authentication SharePoint Context SMTP Credentials

Frequently Asked Questions

Why am I getting an 'Access Denied' error when calling SendEmail?

This usually happens because the user or the App Identity executing the code does not have sufficient permissions on the SharePoint site. Ensure the app has at least 'Write' permissions at the Web level. If using CSOM in a console app, verify that the account used for the ClientContext has a valid mailbox and license.

Can I send HTML emails using Utility.SendEmail?

Yes, the EmailProperties.Body property accepts HTML strings. However, ensure that your HTML is well-formatted. Some older versions of SharePoint may require you to explicitly set the body as HTML depending on the specific API version used.

How do I send attachments with SharePoint CSOM?

The native Utility.SendEmail method does not support attachments. To send attachments, you must use the Microsoft Graph API or a custom SMTP solution as shown in the SMTP section of this guide.

Wrapping Up

Choosing the right way to send emails in SharePoint depends entirely on your specific use case. For simple internal notifications, the CSOM Utility class or REST API is the most integrated and easiest to maintain. If you need more robust features like attachments or external delivery, shifting to SMTP or the Microsoft Graph API is the professional choice.

Always remember to test your permissions in a staging environment before deployment, especially when working with SharePoint Add-ins, to avoid the common pitfalls of authorization errors.