脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python基于SMTP协议发送邮件

python基于SMTP协议发送邮件

2021-07-01 00:02CarolLXW Python

这篇文章主要为大家详细介绍了python基于SMTP协议发送邮件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了python基于SMTP协议发送邮件的具体代码,供大家参考,具体内容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 @Time : 2018/5/31
 @Author : LiuXueWen
 @Site :
 @File : sendEmail.py
 @Software: PyCharm
 @Description: 使用SMTP协议发送邮件,支持同时发送给多个地址,支持同时发送文本信息、超文本信息和多附件
"""
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import os
 
class properties():
 # 设置服务器, "smtp.xx.com"
 mail_host = "smtp.qq.com"
 # 用户名
 mail_user = "@qq.com"
 # 口令
 mail_pass = ""
 # smtp服务器端口,每个服务商提供的邮件服务端口可能不一致,465是腾讯的端口
 mail_port = 465
 # 发送邮件的地址
 sender = "@vip.qq.com"
 # 接收邮件,可设置为你的QQ邮箱或者其他邮箱,list类型,可同时填写多个地址并以,分割
 receivers = "@qq.com","@qq.com"
 # 邮件发送的内容
 messageText = "测试使用\n"
 # 邮件发送的超文本内容
 messageHTML = """
     <!DOCTYPE html>
     <html lang="en">
     <head>
      <meta charset="UTF-8">
      <title>test</title>
     </head>
     <body>
      <img src="http://a.hiphotos.baidu.com/image/pic/item/730e0cf3d7ca7bcb6a172486b2096b63f624a82f.jpg" id="codetool">

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/carolcoral/article/details/80524418

延伸 · 阅读

精彩推荐