We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent7df0908 commitfb56f85Copy full SHA for fb56f85
sendemail.py
@@ -0,0 +1,40 @@
1
+importsmtplib
2
+fromemail.mime.textimportMIMEText
3
+#设置服务器所需信息
4
+
5
+#163邮箱服务器地址
6
+mail_host='smtp.163.com'
7
+#163用户名
8
+mail_user='flypython***'
9
+#密码(163等邮箱为授权码)
10
+mail_pass='7******x'
11
12
+#发送地址
13
+sender='flypython.com'
14
+#发送内容为纯文本
15
+message=MIMEText('Hello World ! This is from FlyPython!','plain','utf-8')
16
+#email主题
17
+message['Subject']='FlyPython'
18
19
+message['From']=sender
20
+#接受地址
21
+receivers= ['flypython.com@gmail.com']
22
+#接受地址的名称
23
+message['To']= ['flypython.com@gmail.com']
24
25
26
+#登录并发送邮件
27
+try:
28
+smtpObj=smtplib.SMTP()
29
+#连接到服务器
30
+smtpObj.connect(mail_host,25)
31
+#登录到服务器
32
+smtpObj.login(mail_user,mail_pass)
33
+#发送
34
+smtpObj.sendmail(
35
+sender,receivers,message.as_string())
36
+#退出
37
+smtpObj.quit()
38
+print('success')
39
+exceptsmtplib.SMTPExceptionase:
40
+print('error',e)#打印错误