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

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
  • Both are great examples, but both doesn't explain my problem, the thing is, Email sends (fine) if we provide at lease 1 To address, else fails. – Shadab Mehdi Feb 11 at 7:00
  • try to add to To = "" (empty value) – Zdeněk Vinduška Feb 11 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.