Point smtplib at the gateway's inbound server instead
of your provider's own SMTP server — everything else about how your application
sends mail stays the same.
STARTTLS (port 587)
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = "Test"
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg.set_content("Hello from the gateway.")
with smtplib.SMTP("smtp.adlerwacht.com", 587) as server:
server.starttls()
server.login("[email protected]", "your-mailbox-password")
server.send_message(msg)
Implicit SSL/TLS (port 465)
with smtplib.SMTP_SSL("smtp.adlerwacht.com", 465) as server:
server.login("[email protected]", "your-mailbox-password")
server.send_message(msg)
Load credentials from an environment variable or a secrets manager rather than
hardcoding them in the script, especially if this code lives in a shared
repository.