Skip to main content
Version: 10 - TBD

ConnectorTypeIMAP

class connector_types.connector_type_imap.ConnectorTypeIMAP

Access an IMAP mailbox.

Supported commands

  • capabilities Query server capabilities Returns a list of IMAP4 capabilities as responded by the server.
  • list_folders List available folders. Returns a list of dictionaries describing the folders on the IMAP server.
  • folder_info Fetch information about a folder Returns a dictionary containing the folder information
  • search Search for messages in a folder. The folder can be specified in the folder input. Search criteria can be specified in the criteria input. Returns a list of message IDs.
  • fetch Fetch messages. Text payloads will be included in the outputs. Other payloads will be stored as Cloudomation Engine files if the store_attachments input is set to True The folder can be specified in the folder input. The message IDs to fetch can be specified in the message_set input. Returns a dictionary describing the fetched messages.
  • add_flags Add flags to messages. The folder can be specified in the folder input. The message IDs to fetch can be specified in the message_set input. The flags to add can be specified in the flags input. Returns a dictionary describing the flags of the messages.
  • get_flags Get flags of messages. The folder can be specified in the folder input. The message IDs to fetch can be specified in the message_set input. Returns a dictionary describing the flags of the messages.
  • remove_flags Remove flags from messages. The folder can be specified in the folder input. The message IDs to fetch can be specified in the message_set input. The flags to remove can be specified in the flags input. Returns a dictionary describing the flags of the messages.
  • set_flags Set flags of messages. The folder can be specified in the folder input. The message IDs to fetch can be specified in the message_set input. The flags to set can be specified in the flags input. Returns a dictionary describing the flags of the messages.
  • move Move messages to a folder The source folder can be specified in the folder input. The target folder can be specified in the target_folder input. The message IDs to fetch can be specified in the message_set input. Requires the MOVE capability of the IMAP server. See RFC 6851.
  • delete Delete messages. The message IDs to delete can be specified in the message_set input. Returns a dictionary describing the flags of the deleted messages.

Input Schema

  • host

    Type: string

  • port

    Type: anyOf

  • use_ssl

    Whether or not to connect using IMAP4-over-SSL.

    Type: boolean

    Default: True

  • login

    Type: anyOf

  • password

    Type: anyOf

  • mode

    The mode to operate in.

    Type: anyOf

  • command

    DEPRECATED. Replaced by mode.mode_name.

  • folder

    DEPRECATED. Replaced by mode.folder.

  • target_folder

    DEPRECATED. Replaced by mode.target_folder.

  • criteria

    DEPRECATED. Replaced by mode.criteria.

  • message_set

    DEPRECATED . Replaced by mode.message_set.

  • store_attachments

    DEPRECATED. Replaced by mode.store_attachments.

  • flags

    DEPRECATED. Replaced by mode.flags.

Output Schema

  • result

    Data

Constants

ssl_context_inputs = ['check_hostname', 'client_cert', 'client_key', 'server_ca']

Example

List all available folders of a mailbox:

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
folders = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='list_folders',
).get('output_value')['result']
this.log(folders=folders)
return this.success('all done')

List all unread (unseen) messages in a folder:

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
message_ids = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='search',
folder='INBOX',
criteria=[
'UNSEEN',
],
).get('output_value')['result']
this.log(message_ids=message_ids)
return this.success('all done')

Fetch a message:

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
messages = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='fetch',
message_set=[
'1,8:15',
],
).get('output_value')['result']
this.log(messages=messages)
return this.success('all done')

Mark a message as unseen:

The flag which is used to track seen/unseen status might differ between IMAP implementations.

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
folders = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='remove_flags',
message_set=[
'15',
],
flags=[
'\Seen',
],
).get('output_value')['result']
this.log(folders=folders)
return this.success('all done')