Buy Me a Coffee? Your support is much appreciated!
Source Code
import requests
from ms_graph import generate_access_token, GRAPH_API_ENDPOINT
APP_ID = '<APP ID>'
SCOPES = ['Mail.Send']
access_token = generate_access_token(app_id=APP_ID, scopes=SCOPES)
headers = {
'Authorization': 'Bearer ' + access_token['access_token']
}
endpoint = GRAPH_API_ENDPOINT + '/me/sendMail'
# endpoint = GRAPH_API_ENDPOINT + '/user/<emial address>'
request_body = {
'message': {
'toRecipients': [
{
'emailAddress': {
'address': '<recipient email address>',
'name': 'DummyAcct'
}
}
],
'subject': 'Check your email2',
'body': {
'contentType': 'text', # or html
'content': 'Check your email for the latest update'
},
'importance': 'low'
}
}
response = requests.post(endpoint, headers=headers, json=request_body)
print(response.status_code)

How do you attach a local file to the email? I am needing to email out once a week an attachment that will have the $(current_date).csv format. Can you help with that?