Send Email from SharePoint Online through JSOM + JavaScript/JQuery

Sending Email from SharePoint Online JavaScript

You need to add following script into an script editor and you can send email though.

<script type="text/javascript">
    function processSendEmails() {

        var from;
        from = $("#txtFrom").val();
        var to;
        to = $("#txtRecipients").val();
        var body;
        body = $("#txtBody").val();
        var subject;
        subject = $("#txtSubject").val();
        sendEmail(from, to, body, subject);

    function sendEmail(from, to, body, subject) {
        // Get the relative url of the site
        var siteurl = _spPageContextInfo.webAbsoluteUrl;
        var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
            contentType: 'application/json',
            url: urlTemplate,
            type: "POST",
            data: JSON.stringify({
                'properties': {
                    '__metadata': {
                        'type': 'SP.Utilities.EmailProperties'
                    'From': from,
                    'To': {
                        'results': [to]
                    'Body': body,
                    'Subject': subject
            headers: {
                "Accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
            success: function (data) {
                alert('Email Sent Successfully');
            error: function (err) {
                alert('Error in sending Email:' + JSON.stringify(err));

Recipients: <br />
<input type="text"
       value="[EMAIL or USER DISPLAY NAME]">
<br />
<br />
<br />
<input type="text"
       value="[EMAIL or USER DISPLAY NAME]"> <br />
<br />
<br />
<input type="text"
       value="test mail from JS"> <br />
<br />
<br />
<input type="text"
       value="email body ..."> <br />
<br />
<a onclick=" processSendEmails(); " href="#">Send </a>

Search This Blog

Link Within Related Posts Plugin for WordPress, Blogger...