Skip to content

Instantly share code, notes, and snippets.

@changkun
Created April 11, 2017 13:59
Show Gist options
  • Save changkun/8ce6da2da380540b70126e37a68d0452 to your computer and use it in GitHub Desktop.
Save changkun/8ce6da2da380540b70126e37a68d0452 to your computer and use it in GitHub Desktop.
Python Email Sender for QQ Mail
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL
# qq mail sending server
host_server = 'smtp.qq.com'
sender_mail = 'SENDER_MAIL'
sender_passcode = 'PASS_CODE'
# receiver mail
receiver='RECIEVER_MAIL'
# mail contents
mail_content = 'python send email test'
# mail title
mail_title = 'Python Email'
def send_mail(receiver='', mail_title='', mail_content=''):
# ssl login
smtp = SMTP_SSL(host_server)
# set_debuglevel() for debug, 1 enable debug, 0 for disable
# smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_mail, sender_passcode)
# construct message
msg = MIMEText(mail_content, "plain", 'utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_mail
msg["To"] = receiver
smtp.sendmail(sender_mail, receiver, msg.as_string())
smtp.quit()
send_mail(receiver=receiver,mail_title=mail_title,mail_content=mail_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment