Office365 Component
Properties Methods Events Configuration Settings Errors
The Office365 component provides an easy way to manage sending and receiving mail in Microsoft 365.
Syntax
cloudmail.Office365
Remarks
This component provides an easy to use interface for Office365 using Microsoft's Graph API. To use the component, first set the Authorization property to a valid OAuth token. The Office365 component 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 component requires authentication via OAuth 2.0. First, perform OAuth authentication using the OAuth component or a separate process. Once complete you should have an authorization string which looks like:
Bearer ya29.AHES6ZSZEJzATdZYjeihDn5W-VrXSsxEZu5p0pclxGdKKQAssign 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 SendMail method will send a message directly. Alternatively, you can create a message draft and then send an existing draft using the SendDraft method. In both cases the properties of the new message are assigned through the Message properties (MessageSubject, MessageBodyContent, MessageCc, 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 MessageInfo collection. MessageInfo is populated when the ListMessages, GetMessage, Search, or ListChanges methods are called.
The ListMessages and ListChanges 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 ListFolders 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 ListMessages is called. If additional messages remain in the folder, the ListMessagesMarker property will be populated. If ListMessages is then called again on the same folder the next page of messages will be fetched. The example below populates MessageInfo 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 component with short descriptions. Click on the links for further details.
Attachments | Collection of attachments listed by the server. |
Authorization | An OAuth Authorization String. |
Categories | Collection of attachments listed by the server. |
ChangeMarker | The page marker for listing changed messages. |
Firewall | A set of properties related to firewall access. |
Folders | Collection of folders listed by the server. |
ListFoldersMarker | The page marker for listing folders. |
ListMessagesMarker | The page marker for listing folders. |
MessageAttachments | A semicolon separated list of files to attach to a message. |
MessageBcc | A comma separated list of recipients for blind carbon copies for a message. |
MessageBodyContent | The body content for a message. |
MessageBodyContentType | The body content type for a message. |
MessageCc | A comma separated list of recipients for carbon copies for a message. |
MessageDeliveryReceipt | Whether a message will request a Delivery Receipt. |
MessageFrom | The author of a message. |
MessageImportance | The importance of a message. |
MessageInfo | Collection of information about retrieved messages. |
MessageReadReceipt | Whether a message will request a Read Receipt. |
MessageReplyTo | A mail address to reply to. |
MessageSubject | The subject of a message. |
MessageTo | A comma separated list of recipients for a message. |
NextChangeMarker | A marker indicating what page of changes to return in the future. |
Select | The parts of a message that should be retrieved. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
AddAttachment | Adds an attachment to an existing message. |
Config | Sets or retrieves a configuration setting. |
Copy | Creates a copy of a message. |
CopyFolder | Copies a folder. |
CreateCategory | Creates a new category. |
CreateDraft | Creates a new email draft. |
CreateFolder | Creates a new folder. |
Delete | Deletes a message. |
DeleteAttachment | Deletes an Attachment. |
DeleteCategory | Deletes a mail category. |
DeleteFolder | Deletes a Folder. |
Forward | Forwards a message. |
GetAttachment | Retrieves a message attachment. |
GetCategory | Retrieves a mail category. |
GetFolder | Retrieves a folder. |
GetMessage | Retrieves a Message. |
ListAttachments | Lists all of a message's attachments. |
ListCategories | Lists all mail categories. |
ListChanges | Lists messages that have been changed within a specified folder. |
ListFolders | Lists the folders found in the parent folder. |
ListMessages | Lists the messages in a folder. |
MoveFolder | Moves a folder. |
MoveMessage | Moves a Message. |
RenameFolder | Renames a Folder. |
Reply | Replies to a message. |
ReplyAll | Reply All to a message. |
Reset | Reset the component. |
Search | Search for messages. |
SendCustomRequest | Send a custom HTTP request. |
SendDraft | Sends an existing Draft. |
SendMail | Sends a new email. |
Update | Updates a message. |
UpdateCategory | Updates a category. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
AttachmentList | Fired when an attachment is retrieved from the server. |
CategoryList | Fired when an attachment is retrieved from the server. |
Error | Information about errors during data delivery. |
FolderList | Fired when a folder is retrieved by the server. |
Log | Fires once for each log message. |
MessageList | Fired when a message is retrieved from the server. |
Transfer | Fired while a document transfers (delivers document). |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
FolderPageSize | Page size for fetching folders. |
MessagePageSize | Page size for fetching messages. |
Prefer | Specifies a preferred content header type. |
QueryParamCount | The 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. |