Envoyez du courrier japonais avec Python3.
#!/bin/env python3
import smtplib
from email.mime.text import MIMEText
import datetime
jp='iso-2022-jp'
# file.Le contenu que vous souhaitez envoyer est inclus dans 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]"
#Utilisé lors de la spécification du sujet
d = datetime.datetime.today()
date = d.strftime("%Y-%m-%d")
msg['Subject'] = date+"Informations d'utilisation"
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")
##référence
## 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