Skip to content

pixelbyaj/msgraph-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

msgraph-email

Microsoft Graph Email API using Python License Downloads PyPI - Downloads PayPal Donate

Installation

msgraph-email is available on PyPI.

    pip install msgraph-email

Import modules

from mail.msgraph import EmailService
from mail.models import EmailMessage,EmailAttachment

Configure an Email Service

emailService = EmailService(tenant_id, client_id, client_secret, email_address)

Process to read an email request

By default it will read unread emails of the 'Inbox' mailfolder

emailMessages= emailService.readEmails() 

Process to send an email request

emailMessage = EmailMessage()
emailMessage.toEmails="[email protected]"
emailMessage.message="Hello"
emailService.sendEmail(message)

Process to read and unread an email request

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)

Make a delete email request

emailMessages = emailService.readEmails()
for email in emailMessages:
    emailService.deleteEmail(email.messageId)