Microsoft Office 365 mailer
from office365 import MSOffice365
mailbox = MSOffice365('username@company.com','password','test@company.com')
mailbox.Messages(q=query,mail_id=mailId,folder_id=folderId)
mails = mailbox.Messages()
list(mails['value'][0])
#[u'IsDeliveryReceiptRequested', u'From', u'HasAttachments', u'WebLink', u'BccRecipients',
# u'ParentFolderId', u'Body', u'Importance', u'ConversationId', u'Categories', u'CcRecipients',
# u'BodyPreview', u'Sender', u'DateTimeCreated', u'@odata.id', u'IsDraft', u'ChangeKey',
# u'DateTimeSent', u'DateTimeReceived', u'DateTimeLastModified', u'ReplyTo', u'ToRecipients',
# u'IsRead', u'IsReadReceiptRequested', u'@odata.etag', u'Id', u'Subject']
mails = mailbox.Messages(q={"Select":["Id","Subject","From"],"top":"50"},folder_id='inbox')
list(mails['value'][0])
#[u'Id', u'From', u'@odata.id', u'Subject', u'@odata.etag']
To get a specific mail
mail = mailbox.Messages(q={"Select":["Id","Subject","From"]},mail_id="AGHJS767828KJDS8UJ892WKJSUIKJSK",folder_id='inbox')
list(mail)
#[u'Id', u'From', u'@odata.id', u'Subject', u'@odata.etag']
mailbox.Sendmail(
Subject=mail_Subject,
Importance=mail_importance,
Body={
"ContentType": ContentType,
"Content": Content
},
ToRecipients=[{
"EmailAddress": {
"Name": ToDisplayName,
"Address": ToEmailAdress
}
}],
Attachments=[list of files],
SaveToSentItems=True
)
mailbox.Sendmail(
Subject="Test Mail",
Importance="High",
Body={
"ContentType": "HTML",
"Content": """<html><body>Hi,<br/>
<h3>This is new test mail</h3><br/>
<code>This mail is generated from system </code>
</body></html>
"""
},
ToRecipients=[{ "EmailAddress": { "Name": "Test", "Address": "test@company.com" }}],
)
mailbox.CreateDraftMessage(
folder_id=folder_id,
Subject=mail_Subject,
Importance=mail_importance,
Body={
"ContentType": ContentType,
"Content": Content
},
ToRecipients=[{
"EmailAddress": {
"Name": ToDisplayName,
"Address": ToEmailAdress
}
}],
Attachments=[list of files]
)
mailbox.CreateDraftMessage(
folder_id='inbox',
Subject="Test Mail",
Importance="High",
Body={
"ContentType": "HTML",
"Content": """<html><body>Hi,<br/>
<h3>This is new test mail</h3><br/>
<code>This mail is generated from system </code>
</body></html>
"""
},
ToRecipients=[{ "EmailAddress": { "Name": "Test", "Address": "test@company.com" }}],
Attachments=[`test1.docx','test2.docx'])
mailbox.CreateFolder(folderId, DisplayName)
mailbox.CreateContact(
GivenName = "Your Name",
EmailAddresses = [{
"Address":"username@company.com",
"Name":"Your Name"
}],
BusinessPhones = ["123-456-7890"])
mailbox.Folders(folder_id=folderId, q=query)
mailbox.Calendars(Calender_id=CalenderId, q=query)
mailbox.CalendarGroups(CalGroup_id=CalGroupId, q=query)
mailbox.Events(Event_id=EventId, q=query)
mailbox.Contacts(self, Contact_id=ContactId, folder_id=folderId, q=query)
mailbox.ContactFolders(Contact_id=ContactId, q=query)