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

Office365

Remarks

This class provides an easy to use interface for Office365 using the Microsoft Graph API v1.0. 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 = "fMI7Q~SmDkDGujXXQkKtaNE5hBQID0SIBmmwP";
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 new 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 = "Subject Text";
office365.MessageImportance = "Low";
office365.MessageBodyContentType = "TEXT";
office365.MessageBodyContent = "Body Text.";
office365.MessageTo = "email@example.com";

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

office365.SendDraft(messageId);

There are also methods for replying or forwarding messages using the Office365 component. The Reply, ReplyAll, and Forward method will send a reply or forward directly. Similarly, you can create a reply or forward draft and then send an existing draft using the SendDraft method. Unlike creating a new message, only the direct methods use the Message properties (MessageSubject, MessageBodyContent, MessageCc, etc.). When using CreateDraft, the draft must first be made then updated using the MessageInfo* properties and Update method.

Sending a Reply with SendDraft:

//Create the reply draft
string originalMessageId = "Message ID";
office365.CreateDraft(1, oringialMessageId);

//Set the new draft MessageInfo fields with desired options
office365.MessageInfo[0].To = "email@example.com";
office365.MessageInfo[0].Subject = "Subject Text";
office365.MessageInfo[0].BodyContentType = "TEXT";
office365.MessageInfo[0].BodyContent = "Body Text";

//Update the draft
office365.Update(office365.MessageInfo[0].Id);

//Send the draft
office365.SendDraft(office365.MessageInfo[0].Id);

Receiving Messages

Information about messages fetched by the component can be accessed through the MessageInfo* properties. MessageInfo* properties is populated when the ListMessages, FetchMessage, 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 Folder* properties.

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* properties 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.

AttachmentCountThe number of records in the Attachment arrays.
AttachmentAttachmentTypeThis property contains the attachment type of the attachment.
AttachmentContentIdThis property contains the value of the unique content identifier of the attachment.
AttachmentContentLocationThis property contains the content location of the attachment.
AttachmentContentTypeThis property contains the content type of the attachment.
AttachmentDataThis property contains the raw data of the attachment.
AttachmentFileThis property contains the local file name associated with the attachment.
AttachmentIdThis property contains the attachment identifier of the attachment.
AttachmentIsInlineThis property is true if the attachment is an inline attachment.
AttachmentLastModifiedDateThis property contains the date and time when the attachment was last modified.
AttachmentNameThis property contains the name of the attachment.
AttachmentSizeThis property contains the size in bytes of the attachment.
AuthorizationAn OAuth Authorization String.
CategoryCountThe number of records in the Category arrays.
CategoryColorThis property contains the color of the category.
CategoryDisplayNameThis property contains the display name of the category.
CategoryIdThis property contains the unique identifier of the category.
ChangeMarkerThe page marker for listing changed messages.
FirewallAutoDetectThis property tells the class whether or not to automatically detect and use firewall system settings, if available.
FirewallTypeThis property determines the type of firewall to connect through.
FirewallHostThis property contains the name or IP address of firewall (optional).
FirewallPasswordThis property contains a password if authentication is to be used when connecting through the firewall.
FirewallPortThis property contains the TCP port for the firewall Host .
FirewallUserThis property contains a user name if authentication is to be used connecting through a firewall.
FolderCountThe number of records in the Folder arrays.
FolderChildFolderCountThe number of child folders the folder has.
FolderChildFoldersThe child folders of the folder.
FolderDisplayNameThe display name of the folder.
FolderIdThe unique identifier of the folder.
FolderMessageRulesThe message rules of the folder.
FolderMessagesThe messages contained in the folder.
FolderMultiValueExtendedPropertiesThe multi-value extended properties defined for the folder.
FolderParentFolderIdThe unique identifier for the folder's parent.
FolderSingleValueExtendedPropertiesThe single-value extended properties defined for the folder.
FolderTotalItemCountThe number of total items in the folder.
FolderUnreadItemCountThe number of unread items in the folder.
ListFoldersMarkerThe page marker for listing folders.
ListMessagesMarkerThe page marker for listing folders.
MessageProvides the raw message content.
MessageAttachmentCountThe number of records in the MessageAttachment arrays.
MessageAttachmentAttachmentTypeThis property contains the attachment type of the attachment.
MessageAttachmentContentIdThis property contains the value of the unique content identifier of the attachment.
MessageAttachmentContentLocationThis property contains the content location of the attachment.
MessageAttachmentContentTypeThis property contains the content type of the attachment.
MessageAttachmentDataThis property contains the raw data of the attachment.
MessageAttachmentFileThis property contains the local file name associated with the attachment.
MessageAttachmentIdThis property contains the attachment identifier of the attachment.
MessageAttachmentIsInlineThis property is true if the attachment is an inline attachment.
MessageAttachmentLastModifiedDateThis property contains the date and time when the attachment was last modified.
MessageAttachmentNameThis property contains the name of the attachment.
MessageAttachmentSizeThis property contains the size in bytes of the attachment.
MessageBccA comma separated list of recipients for blind carbon copies for a message.
MessageBodyContentThe body content for a message.
MessageBodyContentTypeThe body content type for a message.
MessageCcA comma separated list of recipients for carbon copies for a message.
MessageDeliveryReceiptWhether or not a message will request a Delivery Receipt.
MessageFromThe author of a message.
MessageImportanceThe importance of a message.
MessageInfoCountThe number of records in the MessageInfo arrays.
MessageInfoBccThe BCc recipients of a message in a message info listing.
MessageInfoBodyContentThe body content of a message in a message info listing.
MessageInfoBodyContentTypeThe body content type (e.
MessageInfoBodyPreviewThe body preview of a message in a message info listing.
MessageInfoCategoriesThe categories of a message in a message info listing.
MessageInfoCcThe Cc recipients of a message in a message info listing.
MessageInfoConversationIdThe conversation unique identifier of a message in a message info listing.
MessageInfoConversationIndexThe conversation index of a message in a message info listing.
MessageInfoCreatedDateThe date created of a message in a message info listing.
MessageInfoDeliveryReceiptRequestedWhether or not a delivery receipt was requested for a message in a message info listing.
MessageInfoFlagStatusMessage flag in a message info listing.
MessageInfoFromThe sender of a message in a message info listing.
MessageInfoHasAttachmentsWhether or not a message in a message info listing has attachments.
MessageInfoIdThe unique identifier of a message in a message info listing set by Microsoft.
MessageInfoImportanceThe importance of a message in a message info listing.
MessageInfoInferenceClassificationThe inference classification of a message in a message info listing.
MessageInfoIsDraftWhether or not a message in a message info listing is a draft.
MessageInfoIsReadWhether or not a message in a message info listing has been read.
MessageInfoJSONThe full JSON content of a message in a message info listing.
MessageInfoLastModifiedDateThe last modified date of a message in a message info listing.
MessageInfoMessageHeadersThe message headers of a message in a message info listing.
MessageInfoMessageIdThe internet message id for the message as described by rfc2822.
MessageInfoParentFolderIdThe unique identifier of the parent folder of a message in a message info listing.
MessageInfoReadReceiptRequestedWhether or not a read receipt was requested for a message in a message info listing.
MessageInfoReceivedDateThe received date of a message in a message info listing.
MessageInfoReplyToWhere to send replies for a message in a message info listing.
MessageInfoSenderThe sender of a message in a message info listing.
MessageInfoSentDateThe date a message was sent for a message in a message info listing.
MessageInfoSubjectThe subject of a message in a message info listing.
MessageInfoToThe recipients of a message in a message info listing.
MessageInfoWebLinkThe URL to open a message in a message info listing in Outlook on the web.
MessageOtherHeadersThe additional message headers for a message.
MessageReadReceiptWhether or not a message will request a Read Receipt.
MessageReplyToA mail address to reply to.
MessageSubjectThe subject of a message.
MessageToA comma separated list of recipients for a message.
NextChangeMarkerA marker indicating which page of changes to return in the future.
ProxyAuthSchemeThis property is used to tell the class which type of authorization to perform when connecting to the proxy.
ProxyAutoDetectThis property tells the class whether or not to automatically detect and use proxy system settings, if available.
ProxyPasswordThis property contains a password if authentication is to be used for the proxy.
ProxyPortThis property contains the TCP port for the proxy Server (default 80).
ProxyServerIf a proxy Server is given, then the HTTP request is sent to the proxy instead of the server otherwise specified.
ProxySSLThis property determines when to use SSL for the connection to the proxy.
ProxyUserThis property contains a user name, if authentication is to be used for the proxy.
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.

AddAttachmentAdds an attachment to an existing message.
ConfigSets or retrieves a configuration setting.
CopyCreates a copy of a message.
CopyFolderCopies a folder.
CreateCategoryCreates a new category.
CreateDraftCreates a new email draft.
CreateFolderCreates a new folder.
DeleteDeletes a message.
DeleteAttachmentDeletes an attachment.
DeleteCategoryDeletes a mail category.
DeleteFolderDeletes a folder.
FetchAttachmentRetrieves a message attachment.
FetchMessageRetrieves a message.
FetchMessageRawRetrieves the raw message of the specified message ID.
ForwardForward a message.
GetCategoryRetrieves a mail category.
GetFolderRetrieves a folder.
ListAttachmentsLists all of a message's attachments.
ListCategoriesLists all mail categories.
ListChangesLists messages that have been changed within a specified folder.
ListFoldersLists the folders found in the parent folder.
ListMessagesLists the messages in a folder.
MoveFolderMoves a folder.
MoveMessageMoves a message.
RenameFolderRenames a folder.
ReplyReply to a message.
ReplyAllReplyAll to a message.
ResetReset the class.
SearchSearch for messages.
SendCustomRequestSend a custom HTTP request.
SendDraftSends an existing draft.
SendMailSends a new email.
UpdateUpdates a message.
UpdateCategoryUpdates 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.

AttachmentListFired when an attachment is retrieved from the server.
CategoryListFired when an attachment is retrieved from the server.
ErrorInformation about errors during data delivery.
FolderListFired when a folder is retrieved by the server.
LogFires once for each log message.
MessageListFired when a message is retrieved from the server.
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.

AttachmentFragmentSizeSize of fragments when uploading large attachments.
AttachmentSimpleUploadLimitThe threshold to use simple uploads.
FetchMIMEMessageFetch MIME encoded message.
FolderPageSizePage size for fetching folders.
MessagePageSizePage size for fetching messages.
MIMEMessageMIME encoded message to send.
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.
UserIdSets the Id of a shared mailbox to connect to.
XPathProvides a way to point to a specific element in the returned XML or JSON response.
XTextThe text of the current element.
AcceptEncodingUsed to tell the server which types of content encodings the client supports.
AllowHTTPCompressionThis property enables HTTP compression for receiving data.
AllowHTTPFallbackWhether HTTP/2 connections are permitted to fallback to HTTP/1.1.
AppendWhether to append data to LocalFile.
AuthorizationThe Authorization string to be sent to the server.
BytesTransferredContains the number of bytes transferred in the response data.
ChunkSizeSpecifies the chunk size in bytes when using chunked encoding.
CompressHTTPRequestSet to true to compress the body of a PUT or POST request.
EncodeURLIf set to true the URL will be encoded by the class.
FollowRedirectsDetermines what happens when the server issues a redirect.
GetOn302RedirectIf set to true the class will perform a GET on the new location.
HTTP2HeadersWithoutIndexingHTTP2 headers that should not update the dynamic header table with incremental indexing.
HTTPVersionThe version of HTTP used by the class.
IfModifiedSinceA date determining the maximum age of the desired document.
KeepAliveDetermines whether the HTTP connection is closed after completion of the request.
KerberosSPNThe Service Principal Name for the Kerberos Domain Controller.
LogLevelThe level of detail that is logged.
MaxRedirectAttemptsLimits the number of redirects that are followed in a request.
NegotiatedHTTPVersionThe negotiated HTTP version.
OtherHeadersOther headers as determined by the user (optional).
ProxyAuthorizationThe authorization string to be sent to the proxy server.
ProxyAuthSchemeThe authorization scheme to be used for the proxy.
ProxyPasswordA password if authentication is to be used for the proxy.
ProxyPortPort for the proxy server (default 80).
ProxyServerName or IP address of a proxy server (optional).
ProxyUserA user name if authentication is to be used for the proxy.
SentHeadersThe full set of headers as sent by the client.
StatusLineThe first line of the last response from the server.
TransferredDataThe contents of the last response from the server.
TransferredDataLimitThe maximum number of incoming bytes to be stored by the class.
TransferredHeadersThe full set of headers as received from the server.
TransferredRequestThe full request as sent by the client.
UseChunkedEncodingEnables or Disables HTTP chunked encoding for transfers.
UseIDNsWhether to encode hostnames to internationalized domain names.
UsePlatformHTTPClientWhether or not to use the platform HTTP client.
UserAgentInformation about the user agent (browser).
ConnectionTimeoutSets a separate timeout value for establishing a connection.
FirewallAutoDetectTells the class whether or not to automatically detect and use firewall system settings, if available.
FirewallHostName or IP address of firewall (optional).
FirewallPasswordPassword to be used if authentication is to be used when connecting through the firewall.
FirewallPortThe TCP port for the FirewallHost;.
FirewallTypeDetermines the type of firewall to connect through.
FirewallUserA user name if authentication is to be used connecting through a firewall.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
KeepAliveRetryCountThe number of keep-alive packets to be sent before the remotehost is considered disconnected.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
LingerWhen set to True, connections are terminated gracefully.
LingerTimeTime in seconds to have the connection linger.
LocalHostThe name of the local host through which connections are initiated or accepted.
LocalPortThe port in the local host where the class binds.
MaxLineLengthThe maximum amount of data to accumulate when no EOL is found.
MaxTransferRateThe transfer rate limit in bytes per second.
ProxyExceptionsListA semicolon separated list of hosts and IPs to bypass when using a proxy.
TCPKeepAliveDetermines whether or not the keep alive socket option is enabled.
TcpNoDelayWhether or not to delay when sending packets.
UseIPv6Whether to use IPv6.
LogSSLPacketsControls whether SSL packets are logged when using the internal security API.
OpenSSLCADirThe path to a directory containing CA certificates.
OpenSSLCAFileName of the file containing the list of CA's trusted by your application.
OpenSSLCipherListA string that controls the ciphers to be used by SSL.
OpenSSLPrngSeedDataThe data to seed the pseudo random number generator (PRNG).
ReuseSSLSessionDetermines if the SSL session is reused.
SSLCACertFilePathsThe paths to CA certificate files on Unix/Linux.
SSLCACertsA newline separated list of CA certificate to use during SSL client authentication.
SSLCipherStrengthThe minimum cipher strength used for bulk encryption.
SSLEnabledCipherSuitesThe cipher suite to be used in an SSL negotiation.
SSLEnabledProtocolsUsed to enable/disable the supported security protocols.
SSLEnableRenegotiationWhether the renegotiation_info SSL extension is supported.
SSLIncludeCertChainWhether the entire certificate chain is included in the SSLServerAuthentication event.
SSLNegotiatedCipherReturns the negotiated ciphersuite.
SSLNegotiatedCipherStrengthReturns the negotiated ciphersuite strength.
SSLNegotiatedCipherSuiteReturns the negotiated ciphersuite.
SSLNegotiatedKeyExchangeReturns the negotiated key exchange algorithm.
SSLNegotiatedKeyExchangeStrengthReturns the negotiated key exchange algorithm strength.
SSLNegotiatedVersionReturns the negotiated protocol version.
SSLProviderThe name of the security provider to use.
SSLSecurityFlagsFlags that control certificate verification.
SSLServerCACertsA newline separated list of CA certificate to use during SSL server certificate validation.
TLS12SignatureAlgorithmsDefines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True.
TLS12SupportedGroupsThe supported groups for ECC.
TLS13KeyShareGroupsThe groups for which to pregenerate key shares.
TLS13SignatureAlgorithmsThe allowed certificate signature algorithms.
TLS13SupportedGroupsThe supported groups for (EC)DHE key exchange.
AbsoluteTimeoutDetermines whether timeouts are inactivity timeouts or absolute timeouts.
FirewallDataUsed to send extra data to the firewall.
InBufferSizeThe size in bytes of the incoming queue of the socket.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.

Copyright (c) 2022 /n software inc. - All rights reserved.
Cloud Mail 2020 C++ Edition - Version 20.0 [Build 8308]