question

VenildoAmaral-8773 avatar image
0 Votes"
VenildoAmaral-8773 asked ·

Send email with attachment - MS Graph

good night
I am sending email without user authentication, automatic method, this is working, but I would like to attach several files to the email, how to do this?
I am using the following code to send email.

 {"message": {
    "subject": "xxxxxx",
    "body": {
      "contentType": "HTML", "content": "yyyyyyyyyyyyy"},
      "toRecipients": [
        {
          "emailAddress": {
            "address": "ttttt@gmail.com"}
         }
       ]
     }
 }

 POST https://graph.microsoft.com/v1.0/users/{id}/sendMail
 Content-Type application/json
 Authorization Bearer " & Token
 Host graph.microsoft.com"

I know a parameter called attachment, but I was unable to use it pointing a physical file path, I need to point several files to be sent in the email.
How to make?

office-exchange-server-administrationoffice-exchange-server-mailflowoffice-exchange-server-itpromicrosoft-graph-mail
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm using the following code

 {
  "message": 
   {
    "subject": "Envio de email Teste do MS Graph",
    "body": 
    {
     "contentType": "HTML",
     "content": "Testando envio"
    },
    "toRecipients": 
     [
      {
       "emailAddress": 
        {
         "address": "xxxxx@gmail.com"
        }
      }
     ],
    "attachments":
     [
      {
       "@odata.type": "#microsoft.graph.fileAttachment",
       "name": "Teste de Anexo",
       "contentLocation": "e:\ramos.xlsx",
       "isInLine":"true"
      }
     ]
   }
 }
0 Votes 0 ·

@VenildoAmaral-8773
Thank you for your question!

Based off your code, you might have to add the "contentBytes" property since it's required per the fileAttachment resource type. I've also added the Exchange Online and "ms-graph-mail" tags so someone from their team can look into this issue, since the message resource type is a MS Graph API that is not related to AzureAD.


Additional Link:
Graph API Send Mail with Attachments


If you have any other questions, please let me know.
Thank you for your time and patience throughout this issue.

0 Votes 0 ·

0 Answers