Python学习笔记(十四)——发送电子邮件和短信

这篇博客介绍了如何使用Python的SMTP库发送电子邮件和短信,包括解析地址的parseaddr()函数,以及添加邮件主题等关键步骤。教程参考了www.liaoxuefeng.com上的内容。
摘要由CSDN通过智能技术生成

SMTP

#-*- encoding: utf-8 -*-
import os, sys
import smtplib
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText

mailInfo = {
    "from": "15735184252@163.com",
    "to": "qmeng1128@163.com",
    "hostname": "smtp.163.com",
    "username": "15735184252@163.com",
    "password": "xxxxxx",
    "mailsubject": "this is test",
    "mailtext": "hello, this is send mail test.",
    "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"], mailI
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值