GMail Module

Properties   Methods   Events   Configuration Settings   Errors  

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




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 = "";
oauth.ServerTokenURL = "";
oauth.ServerAuthURL = "";
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 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:

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

string messageId = gmail.MessageInfo[0].Id;


Receiving Messages

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

The ListMessages method will list the messages.

By default, the component will fetch one page of 100 messages when ListMessages is called. If additional messages remain in the folder, the NextPageToken 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 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 module with short descriptions. Click on the links for further details.

AttachmentProvides the raw attachment content.
AuthorizationAn OAuth Authorization String.
AutoDecodePartsDetermines whether to automatically decode message parts.
FirewallA set of properties related to firewall access.
MessageProvides the raw message content.
MessageAttachmentsA semicolon separated list of files to attach to a message.
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.
MessageCountThe total number of messages on the mailbox.
MessageFromThe author of a message.
MessageHeadersCollection of the headers of the message.
MessageIndexThe index of the MessageInfo that should be used to populate the MessageHeaders and MessageParts collections.
MessageInfoCollection of information about retrieved messages.
MessagePartsCollection of message parts listed by the server.
MessageSubjectThe subject of a message.
MessageToA comma separated list of recipients for a message.
NextPageTokenThe token to retrieve the next page with data.
ProxyA set of properties related to proxy access.
SSLAcceptServerCertEncodedThe certificate (PEM/base64 encoded).
SSLCertEncodedThe certificate (PEM/base64 encoded).
SSLCertStoreThe name of the certificate store for the client certificate.
SSLCertStorePasswordIf 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.
SSLCertStoreTypeThe type of certificate store for this certificate.
SSLCertSubjectThe subject of the certificate used for client authentication.
SSLServerCertEncodedThe certificate (PEM/base64 encoded).

Method List

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

AddMessageLabelsAdds the specified labels to the message specified by MessageId.
AppendToMailboxImports 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.
CountMessagesGet the total number of messages in the mailbox.
CreateDraftCreates a new email draft.
DeleteDeletes a message.
DeleteDraftDeletes a draft permanently.
DeletePermanentlyDeletes the specified messages permanently.
FetchAttachmentRetrieves a raw attachment.
FetchMessageRetrieves a message including the message parts.
FetchMessageHeadersRetrieves the headers of a message.
FetchMessageInfoRetrieves a message info.
FetchMessageRawRetrieves the raw message of the specified message ID.
ListDraftsLists the drafts in a mailbox.
ListMessagesLists the messages in a mailbox.
RemoveMessageLabelsRemoves the specified labels from the message specified by MessageId.
ResetReset the component.
RestoreRestores a message.
SearchSearch for messages.
SendCustomRequestSend a custom HTTP request.
SendDraftSends an existing Draft.
SendMailSends a new email.

Event List

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

ErrorInformation about errors during data delivery.
LogFires once for each log message.
MessageHeaderFired when a header is retrieved from the server.
MessageInfoFired when a message is retrieved from the server.
MessagePartFired when a message part is retrieved from the server.
SSLServerAuthenticationFired after the server presents its certificate to the client.
SSLStatusShows the progress of the secure connection.
TransferFired while a document transfers (delivers document).

Configuration Settings

The following is a list of configuration settings for the module 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.
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.

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