Microsoft Graph Email API using Python
msgraph-email is available on PyPI.
pip install msgraph-email
from mail.msgraph import EmailService
from mail.models import EmailMessage,EmailAttachment
emailService = EmailService(tenant_id, client_id, client_secret, email_address)
By default it will read unread emails of the 'Inbox' mailfolder
emailMessages= emailService.readEmails()
emailMessage = EmailMessage()
emailMessage.toEmails="[email protected]"
emailMessage.message="Hello"
emailService.sendEmail(message)
emailMessages = emailService.readEmails()
for email in emailMessages:
#mark it read
emailService.markEmailReadUnRead(email.messageId,isRead=True)
#mark it unread
#emailService.markEmailReadUnRead(email.messageId,isRead=False)
emailMessages = emailService.readEmails()
for email in emailMessages:
emailService.deleteEmail(email.messageId)