#!/usr/bin/python
#coding=gbk
import smtplib
from email.mime.text import MIMEText
from urllib.request import urlopen
#从文件读
file_ob=open('/home/mailcontent.txt')
try:
content=file_ob.read()
finally:
file_ob.close()
msg=MIMEText(content,'plain','utf-8')
msg['Subject']='this is a test from python'
msg['From']='from@163.com'
msg['To']='to@qq.com'
#从网页读
f=urlopen('http://www.pcesen.com')
msg=MIMEText(f.read(),'html','utf-8')
msg['Subject']='this is a test from python'
msg['From']='from@163.com'
msg['To']='to@qq.com'
smtp=smtplib.SMTP()
smtp.connect("smtp.163.com","25")
smtp.login('from','password')
smtp.sendmail('from@163.com','to@qq.com',msg.as_string())
smtp.quit()python3 发邮件,从文件读邮件内容和发送html内容
Python邮件发送示例
最新推荐文章于 2022-02-12 18:44:06 发布
本文介绍了一个使用Python发送邮件的示例程序。该程序通过smtplib库连接163邮箱SMTP服务器,并利用urllib库从网站抓取内容作为邮件正文。
1万+

被折叠的 条评论
为什么被折叠?



