python發送郵件腳本ssl 465端口


#coding:utf8
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText

mail_info = {
    "from": "xxxx@qq.com",
    "to": "xxx@qq.com",
    "hostname": "smtp.qq.com",
    "username": "xxx@qq.com",
    "password": "xxx",
    "mail_subject": "test",
    "mail_text": "hello, this is a test email, sended by py",
    "mail_encoding": "utf-8"
}

if __name__ == '__main__':
    #這里使用SMTP_SSL就是默認使用465端口
    smtp = SMTP_SSL(mail_info["hostname"])
    smtp.set_debuglevel(1)
    
    smtp.ehlo(mail_info["hostname"]) smtp.login(mail_info["username"], mail_info["password"]) msg = MIMEText(mail_info["mail_text"], "plain", mail_info["mail_encoding"]) msg["Subject"] = Header(mail_info["mail_subject"], mail_info["mail_encoding"]) msg["from"] = mail_info["from"] msg["to"] = mail_info["to"]
    smtp.sendmail(mail_info["from"], mail_info["to"], msg.as_string()) smtp.quit()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM