JDBC Driver for Gmail

Build 22.0.8462

MailMessages

Create, update, delete, and query Gmail messages.

Note: This schema is defined for all tables. Each table name will be a mailbox folder on the server.

Note: In case the mail contains special characters, the mail content in the message body will be base64 encoded. To retrieve the decoded message you can either decode the content part of the message body or retrieve it using the GetPart Stored procedure.

Table Specific Information

Email address fields contained within this table accept the following formats:

  • 'Friendly Name' <address@company.com>
  • address@company.com
The default Gmail table names contain a backslash; some also contain spaces. You can use square brackets to escape the table names for the default Gmail folders. For example:
SELECT * FROM [Gmail/All Mail]

Select

The results of a query to this table conform to the defaults below:
  • The MessageBody and Headers fields are not returned when listing multiple messages.
  • The default number of messages returned is 100. This can be changed by setting either LIMIT or MaxItems. If you wish to return all mail within a mailbox, specify a value of 0 or -1.

List Messages

To list messages within a specific mailbox, specify the mailbox as the table. The emails will then be listed newest to oldest. Alternatively, you can specify a range of message Ids. The available formats for ranges are below:

  • Return only the message with an Id of 10:
    SELECT * FROM [Inbox] WHERE Id = 10 
  • Return all messages from 10 to 20:
    SELECT * FROM [Inbox] WHERE Id BETWEEN 10 AND 20
  • Return messages 1, 3, 5
    SELECT * FROM [Inbox] WHERE Id IN (1,3,5)

Apply Search Criteria

The driver offers several possibilities for searching through email. You can use search criteria from the following sources in the WHERE clause of a SELECT query:

  • Message fields: To search through mail, specify a value for any of the following columns in the WHERE clause of a SELECT query: To, From, BCC, CC, Subject, MessageBody, Flags, Labels, Size, or Date. Complex statements, nested with parentheses, are supported.

    To, From, BCC, CC, Subject, and MessageBody can be filtered with the following operators: =, !=, and CONTAINS.

    Flags and Labels can be used only with the = and != operators.

    Date can be filtered with the following operators: =, <, <=, >, and >=.

    Size can be used with the < and > operators.

    Note that the CONTAINS function requires full words (For example Test, not Tes), just like the search bar from the UI. For example, the query below returns all messages from either test1@email.com or test2@email.com that contain the text 'Test':

    SELECT * FROM [Gmail/All Mail] WHERE CONTAINS(MessageBody, "Test") AND ([From] = test1@email.com OR [From] = test2@email.com) AND Date > '1-1-2012'

  • Attachments: In addition to searching by standard columns, you can also filter by attachment file names and by whether an email has an attachment:
    SELECT * FROM [Gmail/All Mail] WHERE HasAttachment = 'True' AND Attachments = '.txt'
  • Gmail-specific: ThreadId and MsgId can also be used for filtering with the = and != operators. Additionally, the IN operator can also be used for the MsgId columns (the operator will get translated internally to multiple statements with the = operator).
  • IMAP: As an alternative to the above method of creating search criteria, you can use the SearchCriteria pseudo column to search using any valid IMAP search criteria as specified by RFC.

Insert

Insert statement is used to send mail. The Subject, To, and MessageBody fields are required:

INSERT INTO [Gmail/All Mail] (Subject, MessageBody, To) VALUES ('Test Subject','Body Text','address@company.com')

Update

  • To move an email from one mailbox to another, specify the mailbox in the update:
    UPDATE [Inbox] SET Mailbox = 'NewMailboxName' WHERE Id = 'MessageId'
    The Id may consist of a single message number, a range of messages specified by two message numbers separated by ':' (e.g., "1:5"), or individual message numbers separated by ',' (e.g., "1:5,7,10").
  • When moving an email from one mailbox to another, you may not specify any additional updates.
  • To update the flags, specify one or a list of flags in the update:
    UPDATE [Inbox] SET Flags = 'Seen' WHERE Id = 'MessageId'

    The standard values of flags as specified by the IMAP RFCs are : 'Answered' , 'Flagged' , 'Deleted' ,'Seen' and 'Draft'.

    The flags specified in query will override all email's current flags.

Delete

When you delete messages from Gmail through IMAP, those messages are not technically removed from the server. Instead, Gmail removes the current inbox label and marks the mail as "archived." If you want to permanently delete a message from all folders:

  1. Move it to the [Gmail]/Trash.
  2. Delete it from the [Gmail]/Trash folder.

The Id field is required:

Delete FROM [Inbox] WHERE Id = '2'

Additional Notes

  • By default, the max number of messages returned will be 100. This can be changed by setting either LIMIT or MaxItems. If you wish to return all emails within a mailbox, you will need to specify a value of 0 or -1.
  • By default, the number of messages returned per page will be 25. To change this, you can set the ItemsPerPage pseudo column.
  • All message Ids returned are temporary Ids and may change in subsequent requests to the server.

Columns

Name Type ReadOnly References Description
Id [KEY] String True

The identifier of the mail message.

Mailbox String False

The current mailbox that the item is listed in. Updating this value will move the message to a new mailbox.

Subject String False

The subject of the current message.

FullFrom String True

The sender name and email address of the current message.

From String True

The sender email address of the current message.

FullTo String True

A semicolon-separated list of names and email addresses of the recipients.

To String False

A semicolon-separated list of the email addresses of the recipients.

FullCC String True

A semicolon-separated list of names and email addresses of the CCed recipients.

CC String False

A semicolon-separated list of the email addresses of the CCed recipients.

FullBCC String True

A semicolon-separated list of the names and email addresses of the BCCed recipients. This field is only applicable for sent mail.

BCC String False

A semicolon-separated list of the email addresses of the BCCed recipients. This field is only applicable for sent mail.

Date Datetime True

The date and time the current message was sent.

MessageBody String False

The message body. This field can only be set if you specify a single Id in SELECT.

Attachments String False

A semicolon-separated list of the attachment file names (with the path specified if reading from a file) included in the message.

AttachmentData String False

A semicolon-separated list of the base-64-encoded attachment data included in the message. The file name in the Attachments field must also be specified to use this field.

Size Int True

The size in bytes of the current message.

Flags String False

The flags set on the current message.

Labels String False

The labels of the message, separated by spaces. Gmail treats labels as mailboxes.

ThreadId String True

The Gmail thread Id associated with the current message. Several messages may have the same thread Id.

MsgId String True

The Gmail message Id associated with the current message. This is a globally unique Id assigned by Google separate from the IMAP Id/UID.

PartIds String True

The Id of the message part.

PartFilenames String True

The file name of the message part.

PartContentTypes String True

The content type of the message part.

PartSizes String True

The size of the message part.

Headers String True

The message headers for the specified mail message. This field is only available if you specify a single Id in SELECT or set IncludeMessage connection property to true.

AttachmentHeaders String True

The attachment headers for the specified mail message. This field is only available if you specify a single Id in SELECT or set IncludeMessage connection property to true.

ContentIds String True

The content id headers for the specified mail message. This field is only available if you specify a single Id in SELECT or set IncludeMessage connection property to true.

Pseudo-Columns

Pseudo-column fields are used in the WHERE clause of SELECT statements and offer a more granular control over the tuples that are returned from the data source.

Name Type Description
SearchCriteria String

The search criteria to use for the search operation (i.e., SENTSINCE dd-MMM-yyyy). The exact format of the search criteria is specified by the IMAP RFCs. The string consists of one or more search keys and their corresponding values, if any, separated by spaces. For example: 'SINCE 1-Feb-1994 NOT FROM Smith'.

ItemsPerPage String

The maximum number of items to return per page.

The default value is 25.

IsHTML String

This field sets whether the email has an HTML or plain-text encoding.

The default value is TRUE.

Importance String

The importance of the mail message.

The allowed values are UNSPECIFIED, LOW, NORMAL, HIGH.

The default value is UNSPECIFIED.

Priority String

The priority of the mail message.

The allowed values are UNSPECIFIED, NONURGENT, URGENT, NORMAL.

The default value is UNSPECIFIED.

Sensitivity String

The sensitivity of the mail message.

The allowed values are UNSPECIFIED, PERSONAL, PRIVATE, COMPANYCONFIDENTIAL.

The default value is UNSPECIFIED.

DeliveryNotification String

The email address to send a delivery notification to.

ReadReceipt String

The email address to send a read receipt to.

ShowLabels String

This field sets whether to show labels or not.

The default value is TRUE.

ShowThreadId String

This field sets whether to show the thread Id or not.

The default value is TRUE.

ShowMsgId String

This field sets whether to show the unique Gmail Id or not.

The default value is TRUE.

UIDMode String

If this value is set to true, permanent message Ids are used instead of the default temporary Ids.

The default value is FALSE.

HasAttachments String

If this value is set to true, only messages with attachments will be listed. If false, all messages will be listed.

DownloadAttachments String

If true, attachments will be downloaded with the messages. Available only when specifying a single message Id or the Include Messages connection property is true. By default organizes attachments in subfolders with the message Id as name.

The default value is FALSE.

AttachmentFolder String

The folder to download attachments to. If this is set, AttachmentData will not contain data, which will be written to files. Note: An error will be thrown if filters that can't be supported server-side are included in the criteria. Please refer to the 'Apply Search Criteria' section for a list of supported filters.

EMLFolder String

The folder where the complete MIME message, which is saved as an EML file, is downloaded to. If multiple messages are selected, subfolders will be created for each message.

Overwrite String

This field sets whether or not to overwrite attachments and EML files.

The default value is FALSE.

IncludeMessage String

This field sets whether or not to include the message content in the response.

The default value is FALSE.

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462