gmail@2.0.6
This adaptor exports the following from common:
- alterState()
- combine()
- cursor()
- dataPath()
- dataValue()
- each()
- field()
- fields()
- fn()
- fnIf()
- lastReferenceValue()
- merge()
- sourceValue()
Functions
getContentsFromMessages
getContentsFromMessages(options) ⇒ Operation
Downloads contents from messages of a Gmail account.
| Param | Type | Description |
|---|---|---|
| options | Options | Customized options including desired contents and query. |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | The returned message objects, of the form { messageId, contents } |
| processedIds | An 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.
| Param | Type | Description |
|---|---|---|
| message | SendMessageOptions | Array.<SendMessageOptions> | The message configuration object or array of objects. |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | The 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
| Name | Type | Description |
|---|---|---|
| [type] | string | Message content type. Valid types: from, date, subject, body, archive, file. |
| [name] | string | A custom description for the content type. |
| [archive] | RegExp | string | Identifier 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 | string | Identifier 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] | number | Maximum number of characters to retrieve from the content. |
Options
Configurable options provided to the Gmail adaptor.
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [query] | string | Gmail 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] | string | The user account to retrieve messages from. Defaults to the authenticated user. | |
| [maxResults] | int | Maximum number of messages to process per request. Default is 1000. |
SendMessageOptions
Configurable fields for composing an outbound Gmail message.
Properties
| Name | Type | Description |
|---|---|---|
| to | string | Recipient email address. |
| subject | string | Subject line of the email. |
| body | string | Email body content. |
| [attachments] | Array.<{filename: string, content: (string|Buffer)}> | Optional list of files to attach. |