Cloud Mail 2020 Python Edition

Questions / Feedback?

Office365 Class

Properties   Methods   Events   Configuration Settings   Errors  

The Office365 class provides an easy way to manage sending and receiving mail in Microsoft 365.

Syntax

class cloudmail.Office365

Remarks

This class provides an easy to use interface for Office365 using Microsoft's Graph API. To use the class, first set the authorization property to a valid OAuth token. The Office365 class can be used for sending or creating new messages; retrieving, moving, or copying existing messages; creating, deleting, or copying folders; and several other functionalities supported by the Microsoft Graph API.

This class requires authentication via OAuth 2.0. First, perform OAuth authentication using the OAuth class or a separate process. Once complete you should have an authorization string which looks like:

Bearer ya29.AHES6ZSZEJzATdZYjeihDn5W-VrXSsxEZu5p0pclxGdKKQ
Assign this value to the authorization property before attempting any operations. For Example:
Oauth oauth = new Oauth();
 
oauth.ClientId = "3c65828c-6376-4286-91b5-2381c3904a97"; 
oauth.ClientSecret = "mkk2a2M-B5TQI7o5p_N0fR-CHYVn7e3yH~";
oauth.ServerAuthURL = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
oauth.ServerTokenURL = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
oauth.AuthorizationScope = "user.read mail.readwrite mail.send mailboxsettings.readwrite";
oauth.GrantType = OauthGrantTypes.ogtAuthorizationCode;
 
office365.Authorization. = oauth.GetAuthorization();
Consult the documentation for the service for more information about supported scope values and more details on OAuth authentication.

Sending Messages

There are two methods for sending messages using the Office365 component. The send_mail method will send a message directly. Alternatively, you can create a message draft and then send an existing draft using the send_draft method. In both cases the properties of the new message are assigned through the Message properties (message_subject, message_body_content, message_cc, etc.).

Sending a Message with SendDraft:

office365.MessageSubject = "I am sending an email.";
office365.MessageImportance = "Low";
office365.MessageBodyContentType = "TEXT";
office365.MessageBodyContent = "Just wanted to let you know.";
office365.MessageTo = "reader@tautology.org";

office365.CreateDraft(0, "");
string messageId = office365.MessageInfo[0].Id;

office365.SendDraft(messageId)

Receiving Messages

Information about messages fetched by the component can be accessed through the message_info collection. message_info is populated when the list_messages, get_message, search, or list_changes methods are called.

The list_messages and list_changes methods will respectively list the messages or changed messages in a folder specified by a folderId. To get the ID of a folder, folders can be traversed and read using the list_folders method and the folders collection.

Listing Messages in a Folder:

// Get the folder ID
string folderId = "";

office365.ListFolders(""); // Lists the root child folders.

for (int i = 0; i < office365.Folders.Count; i++)
{
  if (office365.Folders[i].DisplayName.Equals("SpecificFolderName"))
  {
    folderId = office365.Folders[i].Id;
    break;
  }
}

// List folder messages
office365.ListMessages(folderId, "");

By default, the component will fetch one page of 100 messages when list_messages is called. If additional messages remain in the folder, the list_messages_marker property will be populated. If list_messages is then called again on the same folder the next page of messages will be fetched. The example below populates message_info with all the messages in a particular folder.

do {
  office365.ListMessages(folderId);
} while (office365.ListMessagesMarker.Length > 0);

The message page size may also be changed by using the MessagePageSize configuration setting.

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

attachment_countThe number of records in the Attachment arrays.
attachment_attachment_typeThis property contains the attachment type of the attachment.
attachment_content_idThis property contains the value of the unique content identifier of the attachment.
attachment_content_locationThis property contains the content location of the attachment.
attachment_content_typeThis property contains the content type of the attachment.
attachment_dataThis property contains the raw data of the attachment.
attachment_idThis property contains the attachment identifier of the attachment.
attachment_is_inlineThis property is true if the attachment is an inline attachment.
attachment_last_modified_dateThis property contains the date and time when the attachment was last modified.
attachment_local_fileThis property contains the local file name associated with the attachment.
attachment_nameThis property contains the name of the attachment.
attachment_sizeThis property contains the size in bytes of the attachment.
authorizationAn OAuth Authorization String.
category_countThe number of records in the Category arrays.
category_colorThis property contains the color of the category.
category_display_nameThis property contains the display name of the category.
category_idThis property contains the unique identifier of the category.
change_markerThe page marker for listing changed messages.
firewall_auto_detectThis property tells the class whether or not to automatically detect and use firewall system settings, if available.
firewall_typeThis property determines the type of firewall to connect through.
firewall_hostThis property contains the name or IP address of firewall (optional).
firewall_passwordThis property contains a password if authentication is to be used when connecting through the firewall.
firewall_portThis property contains the TCP port for the firewall Host .
firewall_userThis property contains a user name if authentication is to be used connecting through a firewall.
folder_countThe number of records in the Folder arrays.
folder_child_folder_countThe number of child folders the folder has.
folder_child_foldersThe child folders of the folder.
folder_display_nameThe display name of the folder.
folder_idThe unique identifier of the folder.
folder_message_rulesThe message rules of the folder.
folder_messagesThe messages contained in the folder.
folder_multi_value_extended_propertiesThe multi-value extended properties defined for the folder.
folder_parent_folder_idThe unique identifier for the folder's parent.
folder_single_value_extended_propertiesThe single-value extended properties defined for the folder.
folder_total_item_countThe number of total items in the folder.
folder_unread_item_countThe number of unread items in the folder.
list_folders_markerThe page marker for listing folders.
list_messages_markerThe page marker for listing folders.
message_attachmentsA semicolon separated list of files to attach to a message.
message_bccA comma separated list of recipients for blind carbon copies for a message.
message_body_contentThe body content for a message.
message_body_content_typeThe body content type for a message.
message_ccA comma separated list of recipients for carbon copies for a message.
message_delivery_receiptWhether a message will request a Delivery Receipt.
message_fromThe author of a message.
message_importanceThe importance of a message.
message_info_countThe number of records in the MessageInfo arrays.
message_info_bccThe BCc recipients of a message in a message info listing.
message_info_body_contentThe body content of a message in a message info listing.
message_info_body_content_typeThe body content type (e.
message_info_body_previewThe body preview of a message in a message info listing.
message_info_categoriesThe categories of a message in a message info listing.
message_info_cc_recipientsThe Cc recipients of a message in a message info listing.
message_info_conversation_idThe conversation unique identifier of a message in a message info listing.
message_info_conversation_indexThe conversation index of a message in a message info listing.
message_info_created_dateThe date created of a message in a message info listing.
message_info_delivery_receipt_requestedWhether or not a delivery receipt was requested for a message in a message info listing.
message_info_flag_statusMessage flag in a message info listing.
message_info_fromThe sender of a message in a message info listing.
message_info_has_attachmentsWhether or not a message in a message info listing has attachments.
message_info_idThe unique identifier of a message in a message info listing.
message_info_importanceThe importance of a message in a message info listing.
message_info_inference_classificationThe inference classification of a message in a message info listing.
message_info_is_draftWhether or not a message in a message info listing is a draft.
message_info_is_readWhether or not a message in a message info listing has been read.
message_info_jsonThe full JSON content of a message in a message info listing.
message_info_last_modified_dateThe last modified date of a message in a message info listing.
message_info_message_headersThe message headers of a message in a message info listing.
message_info_message_idThe unique identifier of a message in a message info listing.
message_info_parent_folder_idThe unique identifier of the parent folder of a message in a message info listing.
message_info_read_receipt_requestedWhether or not a read receipt was requested for a message in a message info listing.
message_info_received_dateThe received date of a message in a message info listing.
message_info_reply_toWhere to send replies for a message in a message info listing.
message_info_senderThe sender of a message in a message info listing.
message_info_sent_dateThe date a message was sent for a message in a message info listing.
message_info_subjectThe subject of a message in a message info listing.
message_info_toThe recipients of a message in a message info listing.
message_info_web_linkThe URL to open a message in a message info listing in Outlook on the web.
message_read_receiptWhether a message will request a Read Receipt.
message_reply_toA mail address to reply to.
message_subjectThe subject of a message.
message_toA comma separated list of recipients for a message.
next_change_markerA marker indicating what page of changes to return in the future.
selectThe parts of a message that should be retrieved.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

add_attachmentAdds an attachment to an existing message.
configSets or retrieves a configuration setting.
copyCreates a copy of a message.
copy_folderCopies a folder.
create_categoryCreates a new category.
create_draftCreates a new email draft.
create_folderCreates a new folder.
deleteDeletes a message.
delete_attachmentDeletes an Attachment.
delete_categoryDeletes a mail category.
delete_folderDeletes a Folder.
forwardForwards a message.
get_attachmentRetrieves a message attachment.
get_categoryRetrieves a mail category.
get_folderRetrieves a folder.
get_messageRetrieves a Message.
list_attachmentsLists all of a message's attachments.
list_categoriesLists all mail categories.
list_changesLists messages that have been changed within a specified folder.
list_foldersLists the folders found in the parent folder.
list_messagesLists the messages in a folder.
move_folderMoves a folder.
move_messageMoves a Message.
rename_folderRenames a Folder.
replyReplies to a message.
reply_allReply All to a message.
resetReset the class.
searchSearch for messages.
send_custom_requestSend a custom HTTP request.
send_draftSends an existing Draft.
send_mailSends a new email.
updateUpdates a message.
update_categoryUpdates a category.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

on_attachment_listFired when an attachment is retrieved from the server.
on_category_listFired when an attachment is retrieved from the server.
on_errorInformation about errors during data delivery.
on_folder_listFired when a folder is retrieved by the server.
on_logFires once for each log message.
on_message_listFired when a message is retrieved from the server.
on_transferFired while a document transfers (delivers document).

Configuration Settings


The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.

FolderPageSizePage size for fetching folders.
MessagePageSizePage size for fetching messages.
PreferSpecifies a preferred content header type.
QueryParamCountThe number of custom OData Query Parameters.
QueryParamName[i]The name of a custom OData Query Parameter.
QueryParamValue[i]The value of a custom OData Query Parameter.

 
 
Copyright (c) 2021 /n software inc. - All rights reserved.
Cloud Mail 2020 Python Edition - Version 20.0 [Build 7718]