python3模块smtplib实现发送邮件功能

作者:littlethunder 时间:2021-06-10 08:58:52 

本文实例为大家分享了python3 smtplib发送邮件的具体代码,供大家参考,具体内容如下

smtplib模块是smtp简单邮件传输协议客户端的实现,为了通用性,有时候发送邮件的时候要带附件或图片,用email.mime来装载内容。代码如下:


import smtplib
import email.mime.multipart
import email.mime.text

msg=email.mime.multipart.MIMEMultipart()
msg['from']='ustchacker@tom.com'
msg['to']='blablabla@aliyun.com'
msg['subject']='test'
content='''''
你好,
  这是一封自动发送的邮件。

www.ustchacker.com
'''
txt=email.mime.text.MIMEText(content)
msg.attach(txt)

smtp=smtplib
smtp=smtplib.SMTP()
smtp.connect('smtp.tom.com','25')
smtp.login('ustchacker@tom.com','password')
smtp.sendmail('ustchacker@tom.com','blablabla@aliyun.com',str(msg))
smtp.quit()

查看邮箱内容:

python3模块smtplib实现发送邮件功能

可以看到,用Python发送邮件只需要用smtplib的connect(连接到邮件服务器)、login(登陆验证)、sendmail(发送邮件)三个步骤即可,简单方便。

来源:https://blog.csdn.net/littlethunder/article/details/29355403

标签:python,smtplib
0
投稿

猜你喜欢

  • python读取yaml文件后修改写入本地实例

    2021-12-20 02:53:54
  • Python中实现远程调用(RPC、RMI)简单例子

    2022-11-20 06:23:27
  • XML简易教程之四

    2008-09-05 17:19:00
  • Python时间和日期库的实现

    2022-02-22 14:48:28
  • Python中DataFrame判断两列数据是否相等的方法

    2023-12-09 10:17:37
  • python3 判断列表是一个空列表的方法

    2022-02-03 09:40:07
  • PyQt5每天必学之带有标签的复选框

    2021-04-30 05:27:06
  • python Matplotlib模块的使用

    2022-12-26 21:18:37
  • firefox通过XUL实现text-overflow:ellipsis的效果

    2008-07-08 19:12:00
  • php+ajax无刷新上传图片实例代码

    2023-11-17 11:27:58
  • 用python实现k近邻算法的示例代码

    2022-08-28 16:08:58
  • 2010怎么就宅了——我们是设计星球的阿凡达

    2010-03-09 13:26:00
  • Python3.6使用tesseract-ocr的正确方法

    2023-10-24 20:46:28
  • Python LMDB库的使用示例

    2021-01-31 15:11:25
  • Python使用cx_Freeze库生成msi格式安装文件的方法

    2023-02-05 12:26:16
  • php mysql获取表字段名称和字段信息的三种方法

    2023-11-18 22:47:26
  • python 三边测量定位的实现代码

    2023-02-03 08:37:31
  • Jsp+Servlet实现简单登录注册查询

    2023-07-15 18:08:08
  • python生成器的使用方法

    2021-12-03 22:40:49
  • 优化SQLServer数据库服务器内存配置的策略

    2009-05-13 10:25:00
  • asp之家 网络编程 m.aspxhome.com