科学の箱

科学・IT・登山の話題

Python

pythonからoffice365 smtpを利用してメールを送信

投稿日:2018年9月25日 更新日:

Office365の設定はこちらにある。

PythonにおけるSMTPの利用はこちらにある。

下記はサンプルコード


import smtplib
from email.mime.text import MIMEText

SMTP_SERVER="smtp.office365.com"
SMTP_PORT=25

MAIL_ACCOUNT="PLEASE MODIFY"
MAIL_PASS="PLEASE MODIFY"

MAIL_SUBJECT="This is Subject"
MAIL_BODY="This is Body"

def create_message():
  msg = MIMEText(MAIL_BODY)

  msg['Subject'] = MAIL_SUBJECT
  msg['From'] = MAIL_ACCOUNT
  msg['To'] = MAIL_ACCOUNT
  return msg

if __name__ == '__main__':
  smtp = smtplib.SMTP(SMTP_SERVER,SMTP_PORT)
  smtp.connect(SMTP_SERVER)
  smtp.ehlo()
  smtp.starttls()
  smtp.ehlo()
  smtp.login(MAIL_ACCOUNT, MAIL_PASS)
  msg = create_message()
  smtp.sendmail(MAIL_ACCOUNT, MAIL_ACCOUNT, msg.as_string())
  smtp.quit()

メタ情報

inarticle



メタ情報

inarticle



-Python

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

Python + Slack Bot – 2

Slackのチャネルに投稿するにはChanel IDが必要。 Chanel IDは下記から取得できる。 https://api.slack.com/methods/channels.list/test …

no image

pythonで地理情報を取り扱う

pythonでデータ分析をして地理情報に表示したいときに使うパッケージはplotlyである。 plotlyのchropleth map(階級区分図)を利用する。 plotlyについてはこちらでサンプル …

no image

kaggle Titanic Tutorial – 1

KaggleでTitanic tutorialにチャレンジしてみる。 Titanic: Machine Learning from Disaster https://www.kaggle.com/c/ …

no image

wordpress-xmlrpc

WordPressへPythonから投稿してみる。 まずは設定から。説明はこちらにある。 https://python-wordpress-xmlrpc.readthedocs.io/en/lates …

no image

matplotlibのお役立ちリンク

matplotlibのリファレンスが必要ならこちらを参照する。 https://www.labri.fr/perso/nrougier/teaching/matplotlib/ Related pos …

2018年9月
« 6月   10月 »
 12
3456789
10111213141516
17181920212223
24252627282930

side bar top



アーカイブ

カテゴリー