今天闲着就写一下邮件发送,引用python的smtplib包来编写一个简单的发送邮件。望大家多多指教!代码如下:
#!/usr/bin/env/python
# -*- coding: utf-8 -*-
# @File : Client.py
# @Author : t_fengyun
# @Time : 2019/9/10 10:07
# @desc : there is smtp-client
import smtplib
from email.mime.text import MIMEText
from email.header import Header
'''发送的邮箱和密码'''
sender = '17666***@163.com'
password = 'moer15211***'
'''接收者的邮箱'''
mailto_list = ['129961***@qq.com','3155***@qq.com']
'''服务器地址(登录你的服务器邮箱,找到服务器地址。我用的163邮箱)'''
smtp_server = 'smtp.163.com'
msg = MIMEText('python send email test','plain','utf-8')
msg['From'] = sender
msg['To'] = ';'.join(mailto_list)
'''主题'''
subject = 'python smtp test'
msg['Subject'] = Header(subject,'utf-8')
try:
smtpObj = smtplib.SMTP(smtp_server,25)
smtpObj.login(sender,password)
smtpObj.set_debuglevel(1)
smtpObj.sendmail(sender,mailto_list,msg.as_string())
smtpObj.quit()
print('send email success')
except smtplib.SMTPException:
print('Error:email fail')
```