email draft

Copper Contributor

Hi,

 

I'm searching to create an email draft with power automate.

I would like power automate creates a email draft on outlook, i modify some elemets and after i send it

 

is it possible?

 

thanks

 

Bruno

9 Replies

@Bruno62 Yes you can do that by using the Graph API and a power automate flow. you need create the message using the Graph API first Create message - Microsoft Graph v1.0 | Microsoft Learn.

 

the Graph Send an HTTP Request Action, we can create a draft email in one simple action. The content can include dynamic data including title, to, subject, body and of course attachments.

 

image-6.png

 

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.

ok thanks i will try it !
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.
do you know what i have to write in URI ?
thanks
it's written: "message": "URI path is not a valid Graph endpoint, path is neither absolute nor relative or resource/object is not supported for this connector. Resources: groups. Uri: https://graph.microsoft.com/v1.0/me/messages"

Hello@Bruno62 

You can use Graph API. You can select HTTP request Action instead of HTTP request (preview).
 

khushbu_0-1679645161124.png


Reference : https://learn.microsoft.com/en-us/graph/api/user-post-messages?view=graph-rest-1.0&viewFallbackFrom=... 

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.

I am able to send an email on Outlook with the following code (Google Apps Script), but when I change 'me/sendmail' to 'me/messages', I get the following response: {"error":{"code":"UnableToDeserializePostBody","message":"were unable to deserialize "}}

 

function createDraftEmail() {
  var outlookUrl = "https://outlook.office.com/api/v2.0/me/sendmail";

  var accessToken = getAccessToken();

  var headers = {
    "Authorization": "Bearer " + accessToken,
    "Content-type": "application/json"
  };

  var body = {
    "Message": {
      "Subject": "Test email",
      "Body": {
        "ContentType": "HTML",
        "Content": "<html><body>Hello World!</body></html>"
      },
      "ToRecipients": [{
        "EmailAddress": {
          "Address": "email address removed for privacy reasons"
        }
      }],
      "CcRecipients": [{
        "EmailAddress": {
          "Address": "email address removed for privacy reasons"
        }
      }]
    }
  };

  var options = {
    "method": "post",
    "headers": headers,
    "payload": JSON.stringify(body),
    "muteHttpExceptions": true,
  };

  var response = UrlFetchApp.fetch(outlookUrl, options);
  Logger.log(response);
}

 

 

 

Please advise. Here the code for how I am generating the accessToken (minus confidential information), but I don't believe that is where the issue lies:

 

 

function getAccessToken() {
  var outlookOAuthUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
  var clientId = "str";
  var clientSecret = "str";
  var refreshToken = "str";

  var headers = {
    "Content-Type": "application/x-www-form-urlencoded",
  };

  var payload = {
    "grant_type": "refresh_token",
    "client_id": clientId,
    "client_secret": clientSecret,
    "refresh_token": refreshToken,
    "scope": "https://outlook.office.com/mail.readwrite"
  };

  var options = {
    "method": "post",
    "headers": headers,
    "payload": payload,
    "muteHttpExceptions": true,
  };

  var response = UrlFetchApp.fetch(outlookOAuthUrl, options);
  var content = response.getContentText();
  var tokenResponse = JSON.parse(content);
  var accessToken = tokenResponse.access_token;
  return accessToken;
}

 

 

Thank you.