码迷,mamicode.com
首页 > 编程语言 > 详细

python发送邮件脚本ssl 465端口

时间:2017-12-27 18:09:12      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:log   bsp   脚本   odi   port   main   UI   post   string   

#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()

python发送邮件脚本ssl 465端口

标签:log   bsp   脚本   odi   port   main   UI   post   string   

原文地址:https://www.cnblogs.com/Baronboy/p/8125801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!