smtplibを、ご利用のプロバイダー自身のSMTPサーバーではなく
ゲートウェイの受信サーバーに向けてください——
アプリケーションがメールを送信する仕組みの他の部分はそのままです。
STARTTLS(ポート587)
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = "Test"
msg["From"] = "you@yourcompany.com"
msg["To"] = "recipient@example.com"
msg.set_content("Hello from the gateway.")
with smtplib.SMTP("smtp.adlerwacht.com", 587) as server:
server.starttls()
server.login("you@yourcompany.com", "your-mailbox-password")
server.send_message(msg)
暗黙的SSL/TLS(ポート465)
with smtplib.SMTP_SSL("smtp.adlerwacht.com", 465) as server:
server.login("you@yourcompany.com", "your-mailbox-password")
server.send_message(msg)
このコードが共有リポジトリにある場合は特に、認証情報をスクリプトに直接記載
せず、環境変数やシークレットマネージャーから読み込んでください。