Integration · Python
Send email with Python smtplib
The standard library is enough: smtplib with STARTTLS on port 587.
Steps
- 1Build the message with email.message.EmailMessage.
- 2Connect to port 587 and upgrade with STARTTLS.
- 3Log in with your SMTP credential and send.
Connection settings
- Host
- smtp.mailerace.com
- Port
- 587 (STARTTLS) or 465 (TLS)
- Auth
- your SMTP credential
import os, smtplib, ssl
from email.message import EmailMessage
msg = EmailMessage()
msg["From"] = "Acme <[email protected]>"
msg["To"] = "[email protected]"
msg["Subject"] = "Your receipt"
msg.set_content("Thanks for your order!")
with smtplib.SMTP("smtp.mailerace.com", 587) as s:
s.starttls(context=ssl.create_default_context())
s.login(os.environ["MAILERACE_SMTP_USER"], os.environ["MAILERACE_SMTP_PASSWORD"])
s.send_message(msg)Send from Python with confidence
Authenticated, signed and delivered from warm IPs, with a log of every message.