Skip to main content

gmail@1.2.0

getContentsFromMessages(options)
sendMessage(message)

This adaptor exports the following from common:

alterState()
combine()
cursor()
dataPath()
dataValue()
each()
field()
fields()
fn()
fnIf()
http
lastReferenceValue()
merge()
sourceValue()

Functions

getContentsFromMessages

getContentsFromMessages(options) ⇒ Operation

Downloads contents from messages of a Gmail account.

ParamTypeDescription
optionsOptionsCustomized options including desired contents and query.

This operation writes the following keys to state:

State KeyDescription
dataThe returned message objects, of the form { messageId, contents }
processedIdsAn array of string ids processed by this request

Example: Get a message with a specific subject

getContentsFromMessages(
{
query: 'subject:my+test+message'
}
)

Example: Get messages after a specific date, with subject and report.txt attachment

getContentsFromMessages(
{
query: 'after:15/01/2025',
contents: [
'subject',
{ type: 'file', name: 'metadata', file: 'report.txt'}
]
}
)

sendMessage

sendMessage(message) ⇒ Operation

Sends a Gmail message using the provided configuration. Supports attachments and standard email fields like subject, body, and recipients.

ParamTypeDescription
messageSendMessageOptionsThe message configuration object.

This operation writes the following keys to state:

State KeyDescription
dataThe Gmail API response from sending the message.

Example

sendMessage({
to: 'recipient@example.org',
subject: 'Test Message',
body: 'Hello from OpenFn!',
attachments: [
{ filename: 'test.txt', content: 'Some text content' }
]
})

Interfaces

MessageContent

Used to isolate the type of content to retrieve from the message.

Properties

NameTypeDescription
[type]stringMessage content type. Valid types: from, date, subject, body, archive, file.
[name]stringA custom description for the content type.
[archive]RegExp | stringIdentifier to isolate the desired attachment when type is 'archive'. Use a regular expression for pattern matching or a string for a literal match. Required if type is 'archive'.
[file]RegExp | stringIdentifier to isolate the desired attachment when type is 'file' or 'archive'. Use a regular expression for pattern matching or a string for a literal match. Required if type is 'file' or 'archive'.
[maxLength]numberMaximum number of characters to retrieve from the content.

Options

Configurable options provided to the Gmail adaptor.

Properties

NameTypeDefaultDescription
[query]stringGmail search query string.
[contents]Array.<(string|MessageContent)>['from', 'date', 'subject', 'body']An array of strings or MessageContent objects used to specify which parts of the message to retrieve.
[processedIds]Array.<string>Ignore message ids which have already been processed.
[email]stringThe user account to retrieve messages from. Defaults to the authenticated user.
[maxResults]intMaximum number of messages to process per request. Default is 1000.

SendMessageOptions

Configurable fields for composing an outbound Gmail message.

Properties

NameTypeDescription
tostringRecipient email address.
subjectstringSubject line of the email.
bodystringEmail body content.
[attachments]Array.<{filename: string, content: (string|Buffer)}>Optional list of files to attach.