LoginSignup
1
2

More than 3 years have passed since last update.

【忘備録】win32comを使ったメール送信

Posted at

win32comを使ったメール送信

  • Outlookのメールをpythonで送信
  • バッチ内で使用し、ファイルの自動送信
import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application")
my_ol = outlook.CreateItem(0)

# メールフォーマット:1 テキスト, 2 HTML, 3 リッチテキスト
my_ol.BodyFormat = 2 # HTML

my_ol.To = "送信先"
my_ol.Subject = "題名"
my_ol.Body = "本文"

# ファイルを添付(2個)
my_ol.Attachments.Add(r'保存先フォルダ' + r"\添付ファイル1.pdf")
my_ol.Attachments.Add(r'保存先フォルダ' + r"\添付ファイル2.pdf")

# my_ol.Display(True)
my_ol.Send()

1
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
1
2