Configuring SMTP Client¶
Often the default client setup is enough but sometimes it may become necessary to get more control of the connection with your SMTP server. In this discussion we discuss ways to customize the connection.
By default Red Mail uses STARTTLS or opportunistic
TLS in connecting to the SMTP server. You may also change this if needed by changing the
cls_smtp
to other SMTP client classes from :smtplib
in standard library.
Note
Extra keyword arguments in EmailSender
initiation are passed to the SMTP client.
Please see the documentation of the SMTP client you are seeking.
STARTTLS¶
By default, Red Mail uses STARTTLS which is configured as this:
from redmail import EmailSender
from smtplib import SMTP
email = EmailSender(
host="smtp.example.com",
port=587,
cls_smtp=SMTP,
use_starttls=True
)
SMTP TLS¶
You may also continue using TLS:
from redmail import EmailSender
email = EmailSender(
host="smtp.example.com",
port=587,
use_starttls=False
)
SMTP SSL¶
To use SSL:
from redmail import EmailSender
from smtplib import SMTP_SSL
email = EmailSender(
host="smtp.example.com",
port=587,
cls_smtp=SMTP_SSL,
)
You may also pass the SSL context:
from redmail import EmailSender
from smtplib import SMTP_SSL
from ssl import SSLContext
email = EmailSender(
host="smtp.example.com",
port=587,
cls_smtp=SMTP_SSL,
context=SSLContext(...)
)
LMTP¶
To use LMTP:
from redmail import EmailSender
from smtplib import LMTP
email = EmailSender(
host="smtp.example.com",
port=587,
cls_smtp=LMTP
)