Cloud Mail 2020 Python Edition

Questions / Feedback?

GMail Class

Properties   Methods   Events   Configuration Settings   Errors  

The GMail class provides an easy way to manage sending and receiving mail in Gmail.

Syntax

class cloudmail.GMail

Remarks

This class provides an easy to use interface for Gmail using version 3 of the Gmail REST API. To use the class, first set the authorization property to a valid OAuth token. The GMail class can be used for sending or creating new messages; retrieving existing messages; creating, deleting, or sending drafts; and several other functionalities supported by the Gmail 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.AuthorizationScope = "https://www.googleapis.com/auth/gmail.readonly";
oauth.ServerTokenURL = "https://accounts.google.com/o/oauth2/token";
oauth.ServerAuthURL = "https://accounts.google.com/o/oauth2/auth";
oauth.GrantType = OauthGrantTypes.ogtAuthorizationCode;
 
gmail.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 Gmail 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:

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

gmail.CreateDraft();
string messageId = gmail.MessageInfo[0].Id;

gmail.SendDraft(messageId);

Receiving Messages

Information about messages fetched by the component can be accessed through the MessageInfo* properties. The MessageInfo* properties is populated when the list_messages, fetch_message_info, or search methods are called.

The list_messages method will list the messages.

By default, the component will fetch one page of 100 messages when list_messages is called. If additional messages remain in the folder, the next_page_token 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 the MessageInfo* properties with all the messages in the mailbox.

do {
  gmail.ListMessages("", "");
} while (gmail.NextPageToken.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.

attachmentProvides the raw attachment content.
authorizationAn OAuth Authorization String.
auto_decode_partsDetermines whether to automatically decode message parts.
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.
messageProvides the raw message content.
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_countThe total number of messages on the mailbox.
message_fromThe author of a message.
message_header_countThe number of records in the MessageHeader arrays.
message_header_fieldThe property of a message header in a message info listing.
message_header_valueThe value of a message header in a message info listing.
message_indexThe index of the MessageInfo that should be used to populate the MessageHeaders and MessageParts collections.
message_info_countThe number of records in the MessageInfo arrays.
message_info_bccThe blind carbon copy recipient of a message in a message info listing.
message_info_ccThe carbon copy recipient of a message in a message info listing.
message_info_fromThe sender of a message in a message info listing.
message_info_history_idThe history identifier of a message in a message info listing.
message_info_idThe unique identifier of a message in a message info listing.
message_info_internal_dateThe internal date of a message in a message info listing.
message_info_labelsMessage labels in a message info listing.
message_info_sizeThe size of a message in a message info listing.
message_info_snippetThe snippet of a message in a message info listing.
message_info_subjectThe subject of a message in a message info listing.
message_info_thread_idThe thread ID of a message in a message info listing.
message_info_toThe recipients of a message in a message info listing.
message_part_countThe number of records in the MessagePart arrays.
message_part_attachment_idThe attachment ID of a message part in a message info listing.
message_part_content_typeThe content type of a message part in a message info listing.
message_part_dataThe data of a message part in a message info listing.
message_part_filenameThe filename of a message part in a message info listing.
message_part_idThe unique identifier of a message part in a message info listing.
message_part_sizeThe size of a message part in a message info listing.
message_subjectThe subject of a message.
message_toA comma separated list of recipients for a message.
next_page_tokenThe token to retrieve the next page with data.
proxy_auth_schemeThis property is used to tell the class which type of authorization to perform when connecting to the proxy.
proxy_auto_detectThis property tells the class whether or not to automatically detect and use proxy system settings, if available.
proxy_passwordThis property contains a password if authentication is to be used for the proxy.
proxy_portThis property contains the TCP port for the proxy Server (default 80).
proxy_serverIf a proxy Server is given, then the HTTP request is sent to the proxy instead of the server otherwise specified.
proxy_sslThis property determines when to use SSL for the connection to the proxy.
proxy_userThis property contains a user name, if authentication is to be used for the proxy.
ssl_accept_server_cert_encodedThe certificate (PEM/base64 encoded).
ssl_cert_encodedThe certificate (PEM/base64 encoded).
ssl_cert_storeThe name of the certificate store for the client certificate.
ssl_cert_store_passwordIf the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store.
ssl_cert_store_typeThe type of certificate store for this certificate.
ssl_cert_subjectThe subject of the certificate used for client authentication.
ssl_server_cert_encodedThe certificate (PEM/base64 encoded).

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_message_labelsAdds the specified labels to the message specified by MessageId.
append_to_mailboxImports a message into only this user's mailbox, with standard email delivery scanning and classification similar to receiving via SMTP. Does not send a message.
configSets or retrieves a configuration setting.
count_messagesGet the total number of messages in the mailbox.
create_draftCreates a new email draft.
deleteDeletes a message.
delete_draftDeletes a draft permanently.
delete_permanentlyDeletes the specified messages permanently.
fetch_attachmentRetrieves a raw attachment.
fetch_messageRetrieves a message including the message parts.
fetch_message_headersRetrieves the headers of a message.
fetch_message_infoRetrieves a message info.
fetch_message_rawRetrieves the raw message of the specified message ID.
list_draftsLists the drafts in a mailbox.
list_messagesLists the messages in a mailbox.
remove_message_labelsRemoves the specified labels from the message specified by MessageId.
resetReset the class.
restoreRestores a message.
searchSearch for messages.
send_custom_requestSend a custom HTTP request.
send_draftSends an existing Draft.
send_mailSends a new email.

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_errorInformation about errors during data delivery.
on_logFires once for each log message.
on_message_headerFired when a header is retrieved from the server.
on_message_infoFired when a message is retrieved from the server.
on_message_partFired when a message part is retrieved from the server.
on_ssl_server_authenticationFired after the server presents its certificate to the client.
on_ssl_statusShows the progress of the secure connection.
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.

IncludeSpamTrashWhether or not to include the Spam and Trash folders during the message listing.
MessagePageSizePage size for fetching messages.
MIMEMessageMIME encoded message to send.
ResolveLabelNamesWhether or not to resolve the label names to show the display name instead of the id.
ResponseTypeThe level of information to retrieve for a specific email.
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.
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.
SSLCheckCRLWhether to check the Certificate Revocation List for the server certificate.
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 Python Edition - Version 20.0 [Build 8308]