forked from daacheng/PythonBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmail.py
40 lines (32 loc) · 1.01 KB
/
sendmail.py
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
import smtplib
from email import encoders
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
#sender发件人,password服务器授权码, mail_host 服务器地址(QQsmtp) receiver接收者
sender = '[email protected]'
password = '####'
mail_host = 'smtp.qq.com'
#设置邮件信息
msg = MIMEMultipart()
#邮件主题
msg['Subject'] = input("请输入邮件主题: ")
msg['From'] = sender
msg_content = input("请输入正文:")
msg.attach(MIMEText(msg_content,'plain','utf-8'))
#登录并发送
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.set_debuglevel(1)
s.login(sender, password)
#给接收者发送消息
for i in range(len(receives)):
to = receives[i]
msg['To'] = to
s.sendmail(sender, to, msg.as_string())
print('success!')
s.quit()
print('All email has been send over')
except smtplib.SMTPException as e:
print("Failed ,%s",e)