01_Script_Office365 (O365) send mail - Hideboyon/Samples GitHub Wiki

Check point of this script

Module

smtplib
It is how to use smtplib, but basically it is just to create and send MIME, but it will add processing such as login if necessary by setting the SMTP server side.

Emailmessage

Part of script

Reference link

How to set up a multifunction device or application to send email using Office 365 and Microsoft 365
https://docs.microsoft.com/ja-jp/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-office-3

email — An email and MIME handling package https://docs.python.org/3/library/email.html

Motivation

※2020/5/20 update Due to the change of our office policy, Office 365 to 2-step authentication(SMS authentication),the following script now > generates an authentication error.

I am using office365(O365)for my company's email. I used to do the daily manual work extracting attachments from a particular email, but it was a lot of work, so I decided to automate it by Python.

このスクリプトのポイント

参考リンク

Office 365 および Microsoft 365 を使用してメールを送信するように多機能デバイスまたはアプリケーションをセットアップする方法
https://docs.microsoft.com/ja-jp/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-office-3

Pythonでメール送信
https://www.python.ambitious-engineer.com/archives/2034

Python で Office 365 からメールを送信する http://honeotech.hatenablog.com/entry/2018/01/03/023911

email --- 電子メールと MIME 処理のためのパッケージ
https://docs.python.org/ja/3/library/email.html

作ろうと思ったモチベーションとか

※2020/5/20更新 Office365 が2段階認証(SMSによる認証)になったため、下記スクリプトで認証エラーが出るようになった。。。

Office 365(O365)を会社のメールで使っていたので、特定のメールを吸い出して添付府ファイルをDL、そこからデータ整形して再度メールで送信というのを手作業で毎日やっていた。が、めんどうなので自動化しようと思ったのがきっかけ。

※このスクリプトはO365の自分のメールアカウントを使って、メールを送信するだけのもの。