Skip to content

Instantly share code, notes, and snippets.

@sunliwen
Created March 17, 2016 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunliwen/fa0aade25909f7ad41b2 to your computer and use it in GitHub Desktop.
Save sunliwen/fa0aade25909f7ad41b2 to your computer and use it in GitHub Desktop.
smtplib ssl qq mail
import os, sys
import smtplib
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText
mailInfo = {
"from":"user@domain.com",
"to":"someone@anotherdomain.com",
"hostname":"smtp.exmail.qq.com",
"username":"USERNAME",
"password":"PASSWORD",
"mailsubject":"Title",
"mailtext":"Hello World!",
"mailencoding":"utf-8"
}
if __name__ == '__main__':
smtp = SMTP_SSL(mailInfo["hostname"])
smtp.set_debuglevel(1)
smtp.ehlo(mailInfo["hostname"])
smtp.login(mailInfo["username"],mailInfo["password"])
msg = MIMEText(mailInfo["mailtext"],"text",mailInfo["mailencoding"])
msg["Subject"] = Header(mailInfo["mailsubject"],mailInfo["mailencoding"])
msg["from"] = mailInfo["from"]
msg["to"] = mailInfo["to"]
smtp.sendmail(mailInfo["from"], mailInfo["to"], msg.as_string())
smtp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment