python SMTP发送邮件
来源:互联网 发布:牵黄擎苍岂可得乎 编辑:程序博客网 时间:2024/06/10 17:25
SMTP发送邮件的用处是 可以让程序运行出错时给自己的手机发送出错日志。就可以及时刚回来给修改BUG。
代码:
from smtplib import SMTPfrom email.mime.text import MIMETextfrom email.header import Headerdef send_email(SMTP_host, from_account, from_passwd, to_account, subject, content): email_client = SMTP(SMTP_host) email_client.login(from_account, from_passwd) # create msg msg = MIMEText(content, 'plain', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = from_account msg['To'] = to_account email_client.sendmail(from_account, to_account, msg.as_string()) email_client.quit()if __name__ == "__main__": ''' print('请登录您的邮箱!') from_account = input('please input your email: ') from_passwd = input('Password: ') SMTP_host = input('SMTP_host(like smtp.163.com): ') to_account = input('to_send email: ') subject = input('the theme:\n') content = input('Please write your words:\n') send_email(SMTP_host,from_account,from_passwd,to_account,subject,content)''' send_email('smtp.163.com','qton_mail@163.com','*********','qton_pri@163.com','哈哈哪有什么主题','哈哈哪有什么内容 不过是试试程序而已!哈哈')
发送带图片附件邮件
import cv2import numpy as npimport sysimport timeimport smtplib from email.mime.text import MIMEText from email.header import Header from email.mime.multipart import MIMEMultipart sender = 'wbp2010_love@yeah.net'receiver = ['qton_pri@163.com']smtpserver = 'smtp.yeah.net' username = 'wbp2010_love@yeah.net'password = '***********'message = MIMEMultipart()message['From'] = Header("wbp2010_love@yeah.net", 'utf-8')message['To'] = Header("qton_pri@163.com", 'utf-8')subject = 'Qton'message['Subject'] = Header(subject, 'utf-8')message.attach(MIMEText('这是邮件正文哦', 'plain', 'utf-8'))for i in range(1,31):try:time.sleep(1)# cap = cv2.VideoCapture(0)# ret,frame = cap.read()# cv2.imwrite('../../12/000.jpg',frame)# time.sleep(3)att1 = MIMEText(open('F:/Scraping/5/%s.jpg'%i, 'rb').read(), 'base64', 'utf-8')att1["Content-Disposition"] = 'attachment; filename="0.jpg" 'message.attach(att1)print ('添加图片成功')except smtplib.SMTPException:print ('添加图片失败!\\')try:smtp = smtplib.SMTP() smtp.connect(smtpserver)smtp.login(username, password) smtp.sendmail(sender, receiver, message.as_string())smtp.quit()except:print('邮件发送出错!')
0 0
- python smtp发送邮件
- python smtp发送邮件
- Python SMTP发送邮件
- Python SMTP发送邮件
- python smtp 发送邮件
- Python SMTP发送邮件
- Python SMTP发送邮件
- python SMTP发送邮件
- Python SMTP发送邮件
- Python SMTP发送邮件
- Python SMTP发送邮件
- Python SMTP发送邮件
- Python发送邮件(Email SMTP)
- python使用smtp发送邮件
- python下smtp发送邮件
- Python使用SMTP发送邮件
- Python -- 使用SMTP发送邮件
- python笔记---SMTP发送邮件
- python数据类型详解
- hautoj 1268: 小天使改名
- 备考PMP第七天
- 程序运行内存分析
- leetcode 406. Queue Reconstruction by Height
- python SMTP发送邮件
- Linux设备驱动注册
- 【leetcode】palindrome-partitioning-ii
- ajax $.post传值中文乱码!
- LCD 驱动
- MATLAB读取Excel,Txt文件中的数据
- Python 随机数常用方法
- jquery事件--bind()方法
- 性能测试的基本流程