LoginSignup
2
2

More than 1 year has passed since last update.

[自動化]今日の予定を自動でメールに書く方法[Python]

Last updated at Posted at 2020-12-02

概要

  • いちいち、予定表をコピペしてメールに張り付ける作業がだるいので、メールに今日の予定を自動で書く方法を考えました。

実行結果

  • 今日の予定

a.png


メール

b.png


  • 今日の予定をメールに自動で書くことができた!!

コード

import win32com.client
import datetime

# 予定を取得
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
calendar = outlook.GetDefaultFolder(9) # 「9」というのがOutlookの予定表のこと

# 予定を抜き出したい期間を指定
today = datetime.datetime.now()
start_date = datetime.date(today.year, today.month, today.day) 

select_items = [item for item in calendar.Items if start_date == item.start.date()] # 今日の予定を入れるリスト

plans = "" # 今日の予定

# 抜き出した予定を入れる
for select_item in select_items:
    plans = plans + select_item.subject + "\n"
   

# メール作成
object = win32com.client.Dispatch("Outlook.Application")
mail = object.CreateItem(0) 
mail.BodyFormat = 1

# メールの本文
mail.Body = plans

# 作成したメールの表示
mail.Display(True)

  # メール送信
# mail.Send()

参考

【自動化】PythonでOutlookの予定を抜き出す

2
2
1

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