Microsoft Graph API - sending email doesn't work

This topic was automatically generated from Slack. You can find the original thread here.

Chee Sian ng : Hi pipedream community,
I have posted previously with regards on how to generate a new token and I was told that pipedream will handle the token on it’s own, as long as I use the build in graph api authentication module. I tried with some simple graph api’s like the view my profile, to even list my OneDrive structure and it was a success.
However, I am kinda stuck with the sending email portion. I tried to do the same by authenticating myself to pipedream’s built in graph module. After which , I change the api to be
https://graph.microsoft.com/v1.0/me/sendMail

Here’s a list of what I tested. I will not include the codes I used in my workflow yet, just to prevent clogging up this thread.

  1. Checked if I can send using the graph explorer testing page. - Success
  2. Checked if I have added the delegated permissions via my azure. Yes, I have added every single possible API related to email read and send and had “grant admin consent for default directory”
  3. Tried to send with pipedreams default node.js code, but I changed the API to be https://graph.microsoft.com/v1.0/me/sendMail - failed with
    “code”: “ErrorAccessDenied”,
    “message”: "Access is denied. Check credentials and try again
  4. But if I were to insert the access token with the access token from the graph explorer and replace the Authorization: Bearer ${auths.microsoft_graph_api.oauth_access_token}, with the token as a variable, I can send out the email and I received it

5. I know that this access token will expire eventually. Hence, I am wondering, How do I proceed to use pipedream if I wish to use the workflow to send emails using Microsoft Office 365 as a user.

Thanks in advance. Please let me know if you need me to share my code in the workflow to you.

Dylan Sather (Pipedream) : Hi , I believe you’re seeing this error because the Mail.Send OAuth scope is required in order to send mail using that endpoint (see the MSFT docs). Our app doesn’t have that scope added, but I opened a feature request here and we’re looking into it now

Dylan Sather (Pipedream) : we’ve added the Mail.Send scope to the MSFT Graph API integration. Would you mind reconnecting your Microsoft account at Connected Accounts - Pipedream, and try sending the email again?
|

Screen Shot 2021-04-21 at 8.25.38 PM.png

Chee Sian ng : :kissing_heart: It works like a charm… Thank you Dylan. Sending emails with official email service is a great use case for workflows.
Now that it is working for my own consumer Office365 tenant, my next step will only be to test it with my company’s azure

Dylan Sather (Pipedream) : Great to hear!