9/01/2014

Python send mail example, smtplib


import smtplib
from email.mime.text import MIMEText
from email.header import Header

host = 'smtp.gmail.com:587'
me = 'me@gmail.com'
you = 'you@daum.net'
subject = 'I love 파이썬'
contents = 'It is contents'

msg = MIMEText(contents.encode('utf-8'), _subtype='plain', _charset='utf-8')
msg['Subject'] = Header(subject.encode('utf-8'), 'utf-8')
msg['From'] = me
msg['To'] = you

s = smtplib.SMTP(host)
s.starttls()
#print( s.ehlo() )
s.login('ID','PASS')
problems = s.sendmail(me, [you], msg.as_string() )
#print( problems )
s.quit()





No comments:

Post a Comment