smtplib module lets you send email through mySMTP without installing third-party packages. You can use STARTTLS on port 587.
Prerequisites
- Python 3.8 or later
- Your mySMTP username and password from the setup email
- Your mySMTP hostname from the setup email (shown as
relayxx.mysmtp.comin these examples)
STARTTLS on port 587 (recommended)
Replace
relayxx.mysmtp.com with your real hostname from the mySMTP setup email. Load credentials from environment variables, never hardcode them in source files.2525 (also STARTTLS). mySMTP does not support port 465 or SMTP_SSL (implicit TLS).
HTML body with attachment
Common errors
535 Authentication failed
535 Authentication failed
Your username or password is incorrect, or your account is not yet activated. Re-enter credentials exactly as shown in the setup email. See Setting up SMTP credentials.
Connection timeout or refused
Connection timeout or refused
Your network or host may block port 587. Try port 2525 with STARTTLS. See Supported SMTP ports and encryption.
TLS handshake failure
TLS handshake failure
The encryption method does not match the port. Use
starttls() on ports 587 and 2525. mySMTP does not support SMTP_SSL or port 465..png?fit=max&auto=format&n=-Uw4rR8wfyv_xkzc&q=85&s=898bb0b43b6c9dce61441f46ac9ac860)
