In this section, we present how to connect Email accounts to MindsDB.

By connecting your email account to MindsDB, you can utilize various AI models available within MindsDB to summarize emails, detect spam, or even automate email replies.

Please note that currently you can connect Gmail accounts using this integration.


This handler was implemented using standard Python libraries: email, imaplib, and smtplib.

The Email handler is initialized with the following required parameters:

  • email stores an email address used for authentication.
  • password stores a password used for authentication.

At the moment, the handler has only been tested with Gmail accounts.

To use the handler on a Gmail account, you must create an app password following this instruction.

Additionally, the following optional parameters can be passed:

  • smtp_server used to send emails. Defaults to
  • smtp_port used to send emails. Defaults to 587.
  • imap_server used to receive emails. Defaults to

To connect your email account to MindsDB, use the below CREATE DATABASE statement:

CREATE DATABASE email_datasource
WITH ENGINE = 'email',
  "email": "",
  "password": "yourpassword"

It creates a database that comes with the emails table.


Now you can query for emails like this:

FROM email_datasource.emails;

And you can apply filters like this:

SELECT id, to, subject, body
FROM email_datasource.emails
WHERE subject = 'MindsDB'

Or, write emails like this:

INSERT INTO email_datasource.emails(to, subject, body)
VALUES ("", "MindsDB", "Hello from MindsDB!");