0

I send email without user authentication, automatic method.

 {
  "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"
      }
     ]
   }
 }

How do I attach several files to the email?

I know a parameter called attachment, but I was unable to use it to point to a physical file path. I need to point to several files.

How to transform the file into base64 using VBA? Is there an API inside Graph that does this?

Community
  • 1
  • 1
  • As of now you cannot point out the files since `contentLocation` is not supported according to the [document](https://docs.microsoft.com/en-us/graph/api/resources/fileattachment?view=graph-rest-1.0#properties). And I am not from the VBA side but you can try getting the file using this thread(https://stackoverflow.com/questions/20390397/reading-entire-text-file-using-vba) and you can encode the data by following this [thread](https://stackoverflow.com/questions/169907/how-do-i-base64-encode-a-string-efficiently-using-excel-vba) which concentrates on text file, you can give a try with Excel file – Shiva Keshav Varma Oct 26 '20 at 10:12
  • Tks, It helped a lot and solved the problem – Venildo Amaral Oct 26 '20 at 14:32
  • Hi, if the posted answer resolves your question, please mark it as the answer by clicking the check mark. Doing so helps others find answers to their questions. See https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Shiva Keshav Varma Oct 26 '20 at 15:42

3 Answers3

0

Solved, the problem was that I needed to convert to base64

0

As of now you cannot point out the files since contentLocation is not supported according to the document. And I am not from the VBA side but you can try getting the file using this thread and you can encode the data by following this thread which concentrates on text file, you can give a try with Excel file.

Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13
0

You will need to convert the file to base64.

import base64

def encode_base64(attachment_path):
    data = open(attachment_path, 'rb').read()
    base64_encoded = base64.b64encode(data).decode('UTF-8')
    return base64_encoded

Define variable

attachment = encode_base64('c:/your_folder/file.xlsx')

After that you can pass to as args to JSON

"attachments": [
                    {
                        "@odata.type": "#microsoft.graph.fileAttachment",
                        "name": "HappyCodeAgosto.xlsx",
                        "contentType": "application/vnd.ms-excel",
                        "contentBytes": attachment
                    }
                ]
Fernando
  • 1
  • 1