use python to sendmail

python的smtplib 库是 Python 自带的一个模块,用于实现 Simple Mail Transfer Protocol (SMTP) 协议。它可以用来发送电子邮件。是 SMTP 服务器端口号。默认端口号为 25。是邮件内容(需要使用 MIME 编码格式)。是 SMTP 服务器地址,是邮件服务器的账号密码。 阅读详情

文件形式的邮件

[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.text import MIMEText  
  5. from email.header import Header  
  6.   
  7. sender = '***'  
  8. receiver = '***'  
  9. subject = 'python email test'  
  10. smtpserver = 'smtp.163.com'  
  11. username = '***'  
  12. password = '***'  
  13.   
  14. msg = MIMEText('你好','plain','utf-8')#中文需参数‘utf-8’,单字节字符不需要  
  15. msg['Subject'] = Header(subject, 'utf-8')  
  16.   
  17. smtp = smtplib.SMTP()  
  18. smtp.connect('smtp.163.com')  
  19. smtp.login(username, password)  
  20. smtp.sendmail(sender, receiver, msg.as_string())  
  21. smtp.quit()  

HTML形式的邮件

[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.text import MIMEText  
  5.   
  6. sender = '***'  
  7. receiver = '***'  
  8. subject = 'python email test'  
  9. smtpserver = 'smtp.163.com'  
  10. username = '***'  
  11. password = '***'  
  12.   
  13. msg = MIMEText('<html><h1>你好</h1></html>','html','utf-8')  
  14.   
  15. msg['Subject'] = subject  
  16.   
  17. smtp = smtplib.SMTP()  
  18. smtp.connect('smtp.163.com')  
  19. smtp.login(username, password)  
  20. smtp.sendmail(sender, receiver, msg.as_string())  
  21. smtp.quit()  

带图片的HTML邮件

[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.multipart import MIMEMultipart  
  5. from email.mime.text import MIMEText  
  6. from email.mime.image import MIMEImage  
  7.   
  8. sender = '***'  
  9. receiver = '***'  
  10. subject = 'python email test'  
  11. smtpserver = 'smtp.163.com'  
  12. username = '***'  
  13. password = '***'  
  14.   
  15. msgRoot = MIMEMultipart('related')  
  16. msgRoot['Subject'] = 'test message'  
  17.   
  18. msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>good!','html','utf-8')  
  19. msgRoot.attach(msgText)  
  20.   
  21. fp = open('h:\\python\\1.jpg', 'rb')  
  22. msgImage = MIMEImage(fp.read())  
  23. fp.close()  
  24.   
  25. msgImage.add_header('Content-ID', '<image1>')  
  26. msgRoot.attach(msgImage)  
  27.   
  28. smtp = smtplib.SMTP()  
  29. smtp.connect('smtp.163.com')  
  30. smtp.login(username, password)  
  31. smtp.sendmail(sender, receiver, msgRoot.as_string())  
  32. smtp.quit()  
带附件的邮件
[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.multipart import MIMEMultipart  
  5. from email.mime.text import MIMEText  
  6. from email.mime.image import MIMEImage  
  7.   
  8. sender = '***'  
  9. receiver = '***'  
  10. subject = 'python email test'  
  11. smtpserver = 'smtp.163.com'  
  12. username = '***'  
  13. password = '***'  
  14.   
  15. msgRoot = MIMEMultipart('related')  
  16. msgRoot['Subject'] = 'test message'  
  17.   
  18. #构造附件  
  19. att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8')  
  20. att["Content-Type"] = 'application/octet-stream'  
  21. att["Content-Disposition"] = 'attachment; filename="1.jpg"'  
  22. msgRoot.attach(att)  
  23.           
  24. smtp = smtplib.SMTP()  
  25. smtp.connect('smtp.163.com')  
  26. smtp.login(username, password)  
  27. smtp.sendmail(sender, receiver, msgRoot.as_string())  
  28. smtp.quit()  

群邮件

[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.text import MIMEText  
  5.   
  6. sender = '***'  
  7. receiver = ['***','****',……]  
  8. subject = 'python email test'  
  9. smtpserver = 'smtp.163.com'  
  10. username = '***'  
  11. password = '***'  
  12.   
  13. msg = MIMEText('你好','plain','utf-8')  
  14.   
  15. msg['Subject'] = subject  
  16.   
  17. smtp = smtplib.SMTP()  
  18. smtp.connect('smtp.163.com')  
  19. smtp.login(username, password)  
  20. smtp.sendmail(sender, receiver, msg.as_string())  
  21. smtp.quit()  

各种元素都包含的邮件

[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.multipart import MIMEMultipart  
  5. from email.mime.text import MIMEText  
  6. from email.mime.image import MIMEImage  
  7.   
  8. sender = '***'  
  9. receiver = '***'  
  10. subject = 'python email test'  
  11. smtpserver = 'smtp.163.com'  
  12. username = '***'  
  13. password = '***'  
  14.   
  15. # Create message container - the correct MIME type is multipart/alternative.  
  16. msg = MIMEMultipart('alternative')  
  17. msg['Subject'] = "Link"  
  18.   
  19. # Create the body of the message (a plain-text and an HTML version).  
  20. text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"  
  21. html = """\ 
  22. <html> 
  23.   <head></head> 
  24.   <body> 
  25.     <p>Hi!<br> 
  26.        How are you?<br> 
  27.        Here is the <a href="http://www.python.org">link</a> you wanted. 
  28.     </p> 
  29.   </body> 
  30. </html> 
  31. """  
  32.   
  33. # Record the MIME types of both parts - text/plain and text/html.  
  34. part1 = MIMEText(text, 'plain')  
  35. part2 = MIMEText(html, 'html')  
  36.   
  37. # Attach parts into message container.  
  38. # According to RFC 2046, the last part of a multipart message, in this case  
  39. # the HTML message, is best and preferred.  
  40. msg.attach(part1)  
  41. msg.attach(part2)  
  42. #构造附件  
  43. att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8')  
  44. att["Content-Type"] = 'application/octet-stream'  
  45. att["Content-Disposition"] = 'attachment; filename="1.jpg"'  
  46. msg.attach(att)  
  47.      
  48. smtp = smtplib.SMTP()  
  49. smtp.connect('smtp.163.com')  
  50. smtp.login(username, password)  
  51. smtp.sendmail(sender, receiver, msg.as_string())  
  52. smtp.quit()  

基于SSL的邮件

[python] view plain copy
  1. #!/usr/bin/env python3  
  2. #coding: utf-8  
  3. import smtplib  
  4. from email.mime.text import MIMEText  
  5. from email.header import Header  
  6. sender = '***'  
  7. receiver = '***'  
  8. subject = 'python email test'  
  9. smtpserver = 'smtp.163.com'  
  10. username = '***'  
  11. password = '***'  
  12.   
  13. msg = MIMEText('你好','plain','utf-8')#中文需参数‘utf-8’,单字节字符不需要  
  14. msg['Subject'] = Header(subject, 'utf-8')  
  15.   
  16. smtp = smtplib.SMTP()  
  17. smtp.connect('smtp.163.com')  
  18. smtp.ehlo()  
  19. smtp.starttls()  
  20. smtp.ehlo()  
  21. smtp.set_debuglevel(1)  
  22. smtp.login(username, password)  
  23. smtp.sendmail(sender, receiver, msg.as_string())  
  24. smtp.quit() 
fake-mailer:一个简单的python脚本将匿名邮件发送给某人 假邮件 一个简单的python脚本将匿名邮件发送给某人 立即下载

相关推荐

postgresql 数据库 timescaledb 函数time_bucket_gapfill()报错解决及更换 license

最近在工作中使用postgresql 和 timescaledb 的time_bucket_gapfill()函数 报错,让更换license,在网上找了一大圈,没有找到,最后解决了这个问题,这篇文章记录我的解决办法查看timescaledb.license参数命令:show timescaledb.license;修改命令: 结果不行,报错如下:lter system set timescaledb.license=‘timescale’;那只能换包了如果出现上面那种情况,那我们只能先从官网上下载带 '

yang_z_1的博客 3249

3.python 发送邮件之smtplib模块

SMTP(Simple Mail Transfer Protocol)是简单邮件传输协议,它是一组用于由源地址到目的地址的邮件传输规则。 python中对SMTP进行了简单的封装,可以发送纯文本邮件,HTML邮件以及带附件的邮件 python创建SMTP对象语法如下: import smtplib smtpObj = smtplib.SMTP( [host [, port ...

weixin_30606461的博客 1191

基于深度强化学习技术优化无线网络中的资源分配(一)DQN部分代码

这是一个GitHub上的开源项目,链接:https://github.com/alexis-anzaldo/Deep-Reinforcement-Learning-for-resource-allocation-in-wireless-networks该项目旨在通过深度强化学习DQL技术优化无线网络中的资源分配,特别关注小型蜂窝和超密集无线蜂窝网络中的功率控制问题,主要目标是提高DRL模型的学习效率和网络吞吐量。

m0_46292040的博客 1538

四、python-smtplib|pycurl模块

本文讲解smtplib模块+pycurl模块。实现邮件的发送和服务的探测!!!

weixin_57670650的博客 1022

群晖Video Station海报墙插件更新了!手把手教你用c5h12o5插件搞定豆瓣/TMDB搜刮

本文详细介绍了如何使用c5h12o5插件为群晖Video Station配置高效的海报墙系统。该插件支持豆瓣、TMDB等多数据源并行搜刮,智能优先级设置和本地化优化,解决TMDB API失效问题,提升影视库管理体验。包含安装教程、配置策略和高级使用技巧,适合影视爱好者优化NAS媒体库。

weixin_29250403的博客 265

Open3D 基于法线的双边滤波

基于法线的双边滤波是一种用于点云平滑的技术,它结合了点与其邻域点之间的几何距离和法线方向的相似性,从而在去除噪声的同时保留几何特征。这种滤波方法广泛应用于点云处理领域,尤其是在需要保留表面细节和边缘的场景中。

纵马踏花向自由 2500

python发送各类QQ邮件 —— smtplib与email模块

SMTP是发送邮件的协议,Python 2.3版本开始内置对SMTP的支持,可以发送纯文本邮件、HTML邮件以及带附件的邮件。本文以QQ邮件为例,用python发送各类邮件。 Python对SMTP支持主要使用smtplib和email两个模块,email模块负责构造邮件,smtplib模块负责发送邮件。 一、 传输简单邮件 smtplib模块 1. SMTP类定义 smtplib.SMTP([host[,port[,local_hostname[,timeout]]]]) 作为SMTP的构

Hehuyi_In的博客 1万+

浪涌抗扰度部分解读

8.3 测试仪器: 8.3.1浪涌发生器(对于连接到对称通信线的接口采用10/700us的组合波发生器;对于其他情况采用1.2/50us(8/20us)组合波发生器,输出极性正负可调、移相范围0-360°可调,最大重复率至少每分钟1次,开路输出电压0.5-4kV,电源线的话有效效输出阻抗为2Ω,通信线的话有效输出阻抗为40Ω) 8.3.2 耦合/去耦网络 8.3.3 参考接地平板 8...

喵叫兽的博客 2505

Python smtplib的详细介绍

本文详细介绍了Python中的smtplib库,该库用于发送电子邮件。首先,分享如何安装smtplib库,然后演示了连接到SMTP服务器的步骤,包括指定SMTP服务器的主机名和端口以及建立连接。接着,讨论了如何登录到邮箱账户,这通常需要提供发件人的邮箱地址和密码进行身份验证。分享了如何构建电子邮件的内容。这包括设置发件人、收件人、主题、正文和附件等元素。使用MIMEText和对象来构建电子邮件的各个部分。演示了如何发送电子邮件,包括使用方法将邮件内容发送给收件人,并使用。

weixin_68789096的博客 1364

讲透 ABAP CDS 注解名称:简单名、结构化名、@ 与 @<、作用域与分组

本文从开发者角度梳理ABAP CDS注解的命名规则与实战写法,重点解析: 语法规则:@与@<的使用场景、结构化命名规范、作用域唯一性要求 评估机制:ABAP运行时与组件框架的注解处理差异 分组技巧:花括号分组简化重复前缀的书写 实战示例:包含完整CDS View Entity(演示注解分组与@<用法)和ABAP报表(读取打印注解) 常见问题:命名错误导致激活失败、框架忽略等注意事项 最后通过航空预订统计案例,展示如何结合多种注解类型实现业务需求。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 262

自动驾驶感知新方案:YOLOv13多模态(RGB+LiDAR+热成像)融合实战

YOLOv13的RGB+LiDAR+热成像多模态融合方案,解决了自动驾驶感知的鲁棒性问题,通过跨模态特征互补和注意力融合,实现了复杂场景下的高精度检测。本文从架构设计、数据预处理、核心模块实现到车载部署,完成了全流程实战。动态模态权重:根据场景自动调整各模态的权重(如黑夜场景提升热成像权重);端到端3D检测:直接从原始点云与图像进行3D检测,减少预处理步骤;轻量化优化:针对车载设备进一步剪枝量化,提升推理速度。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 534

FreeBSD 10.1 下 Sendmail 对接外部 SMTP 的可信发信配置

邮件发送本质上是身份可信度的传递过程,现代邮箱系统(如Gmail、Outlook)依赖TLS加密、SASL认证、SPF/DKIM签名等机制验证发件方身份。在老旧系统如FreeBSD 10.1中,原生Sendmail默认缺乏这些安全能力,导致邮件被拒收或归入垃圾箱。通过配置Sendmail为Smart Host客户端,结合SASL认证与外部SMTP服务(如Mailgun、腾讯企业邮),可复用专业服务商的IP信誉、证书管理和投递反馈能力,实现合规、稳定、可运维的系统级告警邮件投递。本文聚焦于FreeBSD平台下

weixin_33762130的博客 531

量化交易 米筐 多因子合成(回测中使用)

多因子合成 1、因子合成 将一些相关(高、低)的因子合成一个因子 方法: 使用PCA方式(使用于较强相关性) 2、核心代码 将因子 inc_revenue_ttm 和 operating_revenue_growth_ratio_ttm 合成为一个因子 inc_operating from sklearn.decomposition import PCA pca = PCA(n_components=1) # 因子合并 fund['inc_operating'] = pca.fit_transform(fu

廷益_飞鸟的博客 1062

python使用sendmail在linux下发送邮件

参考链接:How do I send mail from a Python script? 使用linux下的sendmail程序来发送邮件,利用popen函数(python docs关于popen函数)可以直接调用linux系统程序,需要指定程序所在的位置。 #!/usr/bin/python # -*- coding: UTF-8 -*- #Author: Victor Lv

5627

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

python email linux,linux下python使用sendmail发送邮件

本文实例为大家分享了python使用sendmail发送邮件的具体代码,供大家参考,具体内容如下使用linux下的sendmail程序来发送邮件,利用popen函数(python docs关于popen函数)可以直接调用linux系统程序,需要指定程序所在的位置。python代码:#!/usr/bin/python# -*- coding: UTF-8 -*-#Author: Victor LvS...

weixin_42551508的博客 392

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

sendmail安装及SMTP配置

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33790053的博客 790

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

python SendMail 发送邮件

  最近在学习python 时,用到了发送邮件的操作,通过整理总结如下:         一、相关模块介绍       发送邮件主要用到了smtplib和email两个模块,这里首先就两个模块进行一下简单的介绍:      smtplib模块         smtplib.SMTP([host[, port[, local_hostname[, timeout]]]])      SM...

weixin_34008805的博客 488

python_sendmail_监控进程

#! /usr/bin/env python # -*- coding: UTF-8 -*- import smtplib import os import time from email.mime.text import MIMEText mailto_list=['xxx@abc.com','xxxx@abc.com','xxxxx@abc.com'] mail_host="smtp.abc...

zuopiezia的博客 214

php sendmail 抄送,Python发送邮件各种姿势

Python发送邮件各种姿势本章目录Python标准库smtplibPython发送邮件并抄送Python发送邮件带附件Python发送HTML邮件Python发送图片邮件在写脚本时,放到后台运行,想知道执行情况,会通过邮件、SMS(短信)、飞信、微信等方式通知管理员,用的最多的是邮件。在linux下,Shell脚本发送邮件告警是件很简单的事,有现成的邮件服在写脚本时,放到后台运行,想知道执行情况...

weixin_34579167的博客 1090

python发送邮件sendmail简单脚本

#!/usr/bin/env python # _*_ coding:utf-8 _*_ #author charkedy def sendmail(): import smtplib from email.mime.text import MIMEText from email.utils import formataddr msg=MIMEText('邮件内容','plain','utf-8') msg["From"]=formataddr(["凯迪没有拉克".

chao199512的博客 1038

Python sendmail

1 #coding:utf-8 #强制使用utf-8编码格式 2 import smtplib #加载smtplib模块 3 from email.mime.text import MIMEText 4 from email.utils import formataddr 5 my_sender='XXXX' #发件人邮箱账号,为了后面易于维护,所以写成了变量 6 ...

weixin_30642267的博客 217

Linux SendMail 使用外部SMTP服务发送邮件

这个今天刚好用到,就测试了一下。OK了。。因为,PYTHON模块是可以,但SHELL脚本用SHELL发,还是合拍点。。   http://my.oschina.net/duangr/blog/183162   1. Sendmail配置 配置发送邮件的邮箱认证信息 vi /etc/mail.rc  --- 增加如下内容 --- set from=yourname@y...

weixin_33881753的博客 284

Python脚本sendmail

#!/usr/bin/python#-*-coding:utf-8-*-importpyodbcimportpprintimportredisimporturllibimportjsonimportsysimportsmtplibfromemail.mime.textimportMIMETextreload(sys)#sys.setd...

weixin_34258078的博客 143
上一篇: 有时候变量不初始化,就会导致core dump
下一篇: libcurl sendmail
michaelrun
博客等级 码龄19年 93粉丝 50原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值