Skip to content

Instantly share code, notes, and snippets.

@h1code2
Forked from changkun/sendmail.py
Created October 4, 2025 15:42
Show Gist options
  • Save h1code2/678524295a0c2401de74ef0d9a0d7ddd to your computer and use it in GitHub Desktop.
Save h1code2/678524295a0c2401de74ef0d9a0d7ddd 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