Send Japanese emails with Python3.
#!/bin/env python3
import smtplib
from email.mime.text import MIMEText
import datetime
jp='iso-2022-jp'
# file.The content you want to send is included in txt
fp = open('file.txt')
raw_msg = fp.read()
msg = MIMEText(raw_msg.encode(jp), 'plain', jp,)
fp.close()
fromaddr = "[email protected]"
toaddr = "[email protected]"
#Used when specifying Subject
d = datetime.datetime.today()
date = d.strftime("%Y-%m-%d")
msg['Subject'] = date+"Usage information"
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")
##reference
## http://w.builwing.info/2013/09/21/python3-3%E3%81%A7%E3%83%A1%E3%83%BC%E3%83%AB%E9%80%81%E4%BF%A1/
Recommended Posts