0

I am trying to send some subscription emails, need all the email addresses in BCC. I tried something like this

const requestUrl = `${this.baseUrl}/_api/SP.Utilities.Utility.SendEmail`;
const itemObject = {
    'properties': {
    '__metadata': {
        'type': 'SP.Utilities.EmailProperties',
    },
    'From': fromEmail,
    'To': {
        'results': [],
    },
    'BCC': {
        'results': toEmail,
    },
    'Body': body.replace(/\n/g, ''),
    'Subject': subject
    }
};
return this.getFormDigest().pipe(
    concatMap((formDigest) => {
        const headers = {
            'X-RequestDigest': formDigest.d.GetContextWebInformation.FormDigestValue
        };
        return this.restApi.post(requestUrl, '', '', itemObject, headers);
    })
);

But API fails with 400 Bad request

enter image description here

Shadab Mehdi
  • 101
  • 1

1 Answers1

0

I have found two good articles which covers sending emails in SharePoint using SP.Utilities.Utility.SendEmail.

Second link also covers sending Email with AdditionalHeaders.

Sources:

  1. Send email to distribution group stored in a SharePoint list using local email client.
  2. SP.Utilities.Utility.SendEmail with additional headers [javascript].

Update: Please note below points before using SP.Utilities.Utility.SendEmail.

  1. The recipient is limited to a valid SharePoint user for security reasons.
  2. You have to add at least one user in to field to send an Email.
  3. In SharePoint Online it is impossible to use SP.Utilities.Utility.SendEmail method and specify the from field. from field will always be no-reply@sharepointonline.com
Ganesh Sanap - MVP
  • 44,918
  • 21
  • 30
  • 61