đŸ˜± Retired API: SP.Utilities.Utility.SendEmail - move to Microsoft Graph API

Yesterday I received a call from a (now a new 😊) customer, and he complained about a custom app (WebPart) solution. He told me that the app normally sends an email automatically after a user uses a specific function in the app. But at the moment the email is missing from the app. The customer explained to me that the IT members have checked the email settings already and the email account is working fine. I asked for the source code, and I started to debug the solution. Then I found out that the app is still using the old retired SP.Utilities.Utility.SendEmail function to send emails.

I updated the email sending method within the app and implemented a Microsoft Graph-based method. For everyone who needs to send an email within an SPFx app, see the code below.

static async sendEMail(receiver: string, subject: string, bodyText: string, webPartCtx: WebPartContext): Promise<void> { const sendMailMessage = { message: { subject: subject, body: { contentType: 'text', content: bodyText }, toRecipients: [ { emailAddress: { address: receiver } } ] }, saveToSentItems: 'false' }; const graphCtx = await webPartCtx.msGraphClientFactory.getClient('3'); await graphCtx.api(`/users/${wpCtx.pageContext.user.loginName}/sendMail`).post(sendMailMessage) }

And you need to request the permission inside the package-solution.json to use the Send-Mail method.

... "webApiPermissionRequests": [ { "resource": "Microsoft Graph", "scope": "Mail.Send" } ]...

More information about the retired function: Retirement of the SharePoint SendEmail API

Kommentare

Beliebte Posts aus diesem Blog

Power Automate: Abrufen von SharePoint Listenelementen mit ODATA-Filter

SharePoint Online: Optimale BildgrĂ¶ĂŸen fĂŒr Seiten (Teil 1)

Connect-SPOService: The remote server returned an error: (400) Bad Request