#!/bin/env python3 import smtplib from email.mime.text import MIMEText import datetime jp='iso-2022-jp' raw_msg = "hogehoge" msg = MIMEText(raw_msg.encode(jp), 'plain', jp,) fromaddr = "hoge" toaddr = "hogehoge" d = datetime.datetime.today() date = d.strftime("%Y-%m-%d") msg['Subject'] = date msg['From'] = fromaddr msg['To'] = toaddr try: server = smtplib.SMTP("localhost") server.send_message(msg) print("successfully sent email") except Exception: print("Error: unable to send email")
[vagrant@localhost python]$ python3 mail.py
successfully sent email
あれ、こない。vagrantだから? ec2でやってみるか。
ec2からコマンドを打つ
[ec2-user@ip-***-**-**-** html]$ python3 mail.py
successfully sent email
なに、こない。