LoginSignup
3
2

More than 3 years have passed since last update.

【Python】メール送信

Posted at

メール送信スクリプトを作成

mail.py
from email.mime.text import MIMEText
import smtplib

# SMTP認証情報
account = "example.com"
password = "XXXXXXXX"

# 送受信先
to_email = "receiver@example.com"
from_email = "sender@example.com"

# MIMEの作成
subject = "テストタイトル"
message = "テスト本文"
msg = MIMEText(message, "html")
msg["Subject"] = subject
msg["To"] = to_email
msg["From"] = from_email

# メール送信処理
server = smtplib.SMTP("example.com", 587)
server.starttls()
server.login(account, password)
server.send_message(msg)
server.quit()

実行

python mail.py
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2