Configuring for Different Providers

Configuring Red Box is easy. If you have your own IMAP server, you just need to set the host address, port and possibly the credentials. There are also pre-configured sender instances for common email providers:

Provider

Sender instance

Host

Port

Gmail (Google)

redbox.gmail

imap.gmail.com

993

Outlook (Microsoft)

redbox.outlook

outlook.office365.com

993

To use them, you may need to configure your account first (see below).

If you use custom email server (ie. your company’s IMAP server), you need to pass the host and port yourself.

from redbox import EmailBox
email = EmailBox(
    host='<your email server>',
    port=993
)

Depending on company policy, you might also need to pass the username and password:

from redbox import EmailBox
email = EmailBox(
    host='<your IMAP server>',
    port=993,
    username="me@example.com",
    password="<MY PASSWORD>"
)

Note

By default, Red Box uses IMAP4_SSL which should be suitable for majority of cases. However, in some cases you may need to use other protocols. See custom IMAP configuraiton.

Gmail

In order to send emails using Gmail, you need to:

When you have your application password you can use Red Box’s gmail object that has the Gmail server pre-configured:

from redbox import gmail
gmail.username = 'example@gmail.com' # Your Gmail address
gmail.password = '<APP PASSWORD>'

# And then you can send emails
gmail.send(
    subject="Example email",
    receivers=['you@example.com'],
    text="Hi, this is an email."
)

Outlook

You may also send emails from MS Outlook. To do so, you just need to have a Microsoft account. There is a pre-configured sender which you may use:

from redbox import outlook
outlook.username = 'example@hotmail.com'
outlook.password = '<YOUR PASSWORD>'

# And then you can send emails
outlook.send(
    subject="Example email",
    receivers=['you@example.com'],
    text="Hi, this is an email."
)

Custom Configuration

You can also use other IMAP objects as well from imaplib.

import imaplib
from redbox import EmailBox

email = EmailBox(
    host='<your IMAP server>',
    port=993,
    cls_imap=imaplib.IMAP4
)

If your IMAP server uses STARTTLS:

import imaplib
from redbox import EmailBox

email = EmailBox(
    host='<your IMAP server>',
    port=993,
    cls_imap=imaplib.IMAP4,
    starttls=True
)