GMail Component
Properties Methods Events Configuration Settings Errors
The GMail component provides an easy way to manage sending and receiving mail in Gmail.
Syntax
cloudmail.Gmail
Remarks
This component provides an easy to use interface for Gmail using Gmail API. To use the component, first set the Authorization property to a valid OAuth token. The GMail component 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 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.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 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 = "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 collection. MessageInfo 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 MessageInfo 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 component with short descriptions. Click on the links for further details.
Attachment | Provides the raw attachment content. |
Authorization | An OAuth Authorization String. |
AutoDecodeParts | Determines whether to automatically decode message parts. |
Firewall | A set of properties related to firewall access. |
Message | Provides the raw message content. |
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. |
MessageCount | The total number of messages on the mailbox. |
MessageFrom | The author of a message. |
MessageHeaders | Collection of the headers of the message. |
MessageIndex | The index of the MessageInfo that should be used to populate the MessageHeaders and MessageParts collections. |
MessageInfo | Collection of information about retrieved messages. |
MessageParts | Collection of message parts listed by the server. |
MessageSubject | The subject of a message. |
MessageTo | A comma separated list of recipients for a message. |
NextPageToken | The token to retrieve the next page with data. |
Proxy | A set of properties related to proxy access. |
SSLAcceptServerCert | Instructs the component to unconditionally accept the server certificate that matches the supplied certificate. |
SSLCert | The certificate to be used during SSL negotiation. |
SSLServerCert | The server certificate for the last established connection. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
AddMessageLabels | Adds the specified labels to the message specified by MessageId. |
AppendToMailbox | Imports 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. |
Config | Sets or retrieves a configuration setting. |
CountMessages | Get the total number of messages in the mailbox. |
CreateDraft | Creates a new email draft. |
Delete | Deletes a message. |
DeleteDraft | Deletes a draft permanently. |
DeletePermanently | Deletes the specified messages permanently. |
FetchAttachment | Retrieves a raw attachment. |
FetchMessage | Retrieves a message including the message parts. |
FetchMessageHeaders | Retrieves the headers of a message. |
FetchMessageInfo | Retrieves a message info. |
FetchMessageRaw | Retrieves the message text of the specified message ID. |
ListDrafts | Lists the drafts in a mailbox. |
ListMessages | Lists the messages in a mailbox. |
RemoveMessageLabels | Removes the specified labels from the message specified by MessageId. |
Reset | Reset the component. |
Restore | Restores a message. |
Search | Search for messages. |
SendCustomRequest | Send a custom HTTP request. |
SendDraft | Sends an existing Draft. |
SendMail | Sends a new email. |
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.
Error | Information about errors during data delivery. |
Log | Fires once for each log message. |
MessageHeader | Fired when a header is retrieved from the server. |
MessageInfo | Fired when a message is retrieved from the server. |
MessagePart | Fired when a message part is retrieved from the server. |
SSLServerAuthentication | Fired after the server presents its certificate to the client. |
SSLStatus | Shows the progress of the secure connection. |
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.
IncludeSpamTrash | Whether or not to include the Spam and Trash folders during the message listing. |
MessagePageSize | Page size for fetching messages. |
ResolveLabelNames | Whether or not to resolve the label names to show the display name instead of the id. |
ResponseType | The level of information to retrieve for a specific email. |