Send Email in SharePoint with SharePoint REST API and PnPjs : What You Need to Know

Sending emails in SharePoint is one of the most common automation tasks developers and power users handle. Whether it’s notifying users about a change, approval, or an update, automating this functionality boosts productivity and improves the user experience.

Let’s explore how to send email in SharePoint using the SharePoint REST API and PnPjs, discuss best practices, real-life use cases, cover what you need to know, and even compare it with alternative approaches like Power Automate and SP.Utilities.


โœ… What Is It?

In SharePoint Online, you can send emails programmatically using:

  • The SharePoint REST API (/_api/SP.Utilities.Utility.SendEmail)
  • PnPjs, a lightweight JavaScript library that simplifies interactions with SharePoint REST APIs

These methods allow you to trigger emails from custom forms, web parts, or workflows without needing external mail servers or third-party connectors.


๐Ÿ’ก Why Do We Need It?

Sometimes SharePointโ€™s out-of-the-box notifications arenโ€™t flexible enough. For instance:

  • You need to send a formatted HTML email on item creation.
  • You want to CC or BCC users.
  • You need to trigger emails based on custom logic from a form or app page.

This is where custom email solutions with REST API or PnPjs shine.


๐Ÿ‘ฅ Who Uses It?
  • SharePoint Developers creating custom apps or web parts
  • Power Users integrating JavaScript into pages or modern forms
  • IT Admins managing automation without relying entirely on Power Automate
  • Consultants creating scalable notification features

๐Ÿ“ฆ Applications That Use It
  • SharePoint Framework (SPFx) WebParts
  • Script Editor / Modern Script WebParts with JavaScript
  • Custom Forms in SharePoint Lists
  • Power Apps with HTTP request connectors
  • Flow/Power Automate (alternative option)

๐Ÿ› ๏ธ Sample Implementations
๐Ÿ”น Option 1: Send Email Using SharePoint REST API
function sendEmail() {
    var siteUrl = _spPageContextInfo.webAbsoluteUrl;

    $.ajax({
        contentType: 'application/json',
        url: siteUrl + "/_api/SP.Utilities.Utility.SendEmail",
        type: "POST",
        data: JSON.stringify({
            'properties': {
                '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
                'To': { 'results': ['user@domain.com'] },
                'Subject': 'Custom Notification',
                'Body': 'Hello! This is a custom email from SharePoint.'
            }
        }),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function () {
            console.log('Email sent successfully!');
        },
        error: function (err) {
            console.error('Error sending email: ', err);
        }
    });
}

๐Ÿ”น Option 2: Send Email Using PnPjs
import { sp } from "@pnp/sp/presets/all";

sp.utility.sendEmail({
    To: ["user@domain.com"],
    Subject: "PnPjs Email",
    Body: "This email was sent using PnPjs!",
}).then(_ => {
    console.log("Email Sent!");
}).catch(console.error);

โœ… Best Practices
  • Always validate email addresses before sending
  • Use HTML format carefully โ€” sanitize input to prevent injection
  • Use try/catch or .catch() blocks for error handling
  • Avoid sending emails inside loops without batching
  • Log success/failure for auditing

๐Ÿง  Things You Should Know
  • Emails are sent from no-reply@sharepointonline.com
  • You canโ€™t change the sender without external SMTP services
  • User permissions: Sender must have access to use utility service
  • Rate limits apply โ€” donโ€™t flood the system
  • Not supported in SharePoint 2013 On-Prem without additional setup

๐Ÿ”„ Alternatives & Comparisons
FeatureREST APIPnPjsPower AutomateSP.Utilities in CSOM
Setup ComplexityModerateEasy (with SPFx)Very EasyAdvanced (for legacy)
UI IntegrationRequires Custom DevGreat for SPFxForm-BasedLimited UI
Error HandlingManualPromise-basedBuilt-in UI loggingComplex
Authentication HandlingManual Token/DigestHandles with SPFx contextHandled by FlowNeeds legacy auth
HTML SupportYesYesYesYes
ReusabilityHighHighModerate (per flow basis)Low
Best ForCustom Webparts, FormsSPFx-based apps, modern formsBusiness users, quick winsOn-prem scripting

๐Ÿ“Œ Real-World Use Cases
  • Notify a manager when a list item is updated
  • Send onboarding emails from a custom HR form
  • Alert security team on suspicious activity logs
  • Share download links to external users securely
  • Send confirmation emails on form submissions

โš–๏ธ Pros and Cons
โœ… Pros
  • Lightweight and flexible
  • Great for custom UI experiences
  • Integrates well with modern SharePoint development
โŒ Cons
  • Limited customization of sender
  • Requires permissions and tokens
  • Not beginner-friendly for non-devs

๐Ÿ”— Useful References

Whether you’re working on a custom form, SPFx WebPart, or a user-driven portal, sending emails via SharePoint REST API or PnPjs gives you control, power, and flexibility. It’s ideal for developers who need more than just simple notifications and want to create a consistent and branded user experience.

If you’re new to PnPjs, Iโ€™d recommend starting there โ€” it simplifies development and future-proofs your code. For power users and low-code enthusiasts, Power Automate might be a better fit for quick wins.


Leave a Comment

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