Created
May 8, 2012 04:06
-
-
Save wynemo/2632474 to your computer and use it in GitHub Desktop.
smtp 测试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mimetypes | |
from email.MIMEMultipart import MIMEMultipart | |
from email.Header import Header | |
from email.MIMEText import MIMEText | |
from email.MIMEImage import MIMEImage | |
from time import sleep | |
import smtplib | |
def sendEmail(htmlText): | |
msgRoot = MIMEMultipart('related') | |
msgRoot['Subject'] = 'testtttttttttttt' | |
msgRoot['From'] = user | |
msgRoot['To'] = user | |
msgRoot.preamble = 'This is a multi-part message in MIME format.' | |
msgAlternative = MIMEMultipart('alternative') | |
msgRoot.attach(msgAlternative) | |
msgText = MIMEText(htmlText, 'html', 'utf-8') | |
msgText.set_charset("utf-8") | |
msgAlternative.attach(msgText) | |
smtp =smtplib.SMTP('smtp.gmail.com', port=587, timeout=20) | |
smtp.ehlo() | |
smtp.starttls() | |
smtp.ehlo() | |
smtp.login(user, passwd) | |
smtp.sendmail(user, user, msgRoot.as_string()) | |
sleep(5) | |
smtp.quit() | |
return | |
user = raw_input('user:') | |
passwd = raw_input('password:') | |
sendEmail('中文毫无压力abcはじめまして') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment