|
1 | 1 | import smtplib |
2 | | -import time |
3 | | -import xlrd |
4 | | -from email import encoders |
5 | | -from email.header import Header |
6 | | -from email.mime.multipart import MIMEMultipart |
7 | | -from email.mime.text import MIMEText |
8 | | -from email.utils import parseaddr, formataddr |
9 | | -from email.mime.application import MIMEApplication |
| 2 | +from email import (header) |
| 3 | +from email.mime import (text, application, multipart) |
10 | 4 | from datetime import date, datetime |
| 5 | +import time |
11 | 6 |
|
12 | 7 |
|
13 | 8 | def sender_mail(): |
14 | 9 | smt_p = smtplib.SMTP() # 创建对象 |
15 | 10 | smt_p.connect(host='smtp.qq.com', port=25) # 设置smtp服务器 |
16 | 11 | sender = '113097485@qq.com' |
17 | | - password = "*****************" # 在qq邮箱设置开启SMTP服务并复制授权码到password |
| 12 | + password = "rmedemkcefbkbhjc" # 在qq邮箱设置开启SMTP服务并复制授权码到password |
18 | 13 | smt_p.login(sender, password) # 进行邮箱登录一次,填写你本人的邮箱 |
19 | | - receiver_addresses, count_num = ['guozhennianhua@163.com'], 1 |
| 14 | + receiver_addresses, count_num = [ |
| 15 | + 'guozhennianhua@163.com', 'xiaoxiazi99@163.com'], 1 |
20 | 16 | for email_address in receiver_addresses: |
21 | 17 | # 表格中邮箱格式不正确,如有空字符,在发邮件的时候会出现异常报错,捕获到这些异常就跳过 |
22 | 18 | try: |
23 | | - msg = MIMEMultipart() |
| 19 | + msg = multipart.MIMEMultipart() |
24 | 20 | msg['From'] = "zhenguo" # 设置发邮件人 |
25 | 21 | msg['To'] = email_address # 收件人 |
26 | 22 | # msg['Cc'] = 'guozhennianhua@163.com' |
27 | | - msg['subject'] = Header('通知', 'utf-8') # 主题名称 |
28 | | - msg.attach( |
29 | | - MIMEText('您好!\n这是一封测试邮件,使用Python实现自动发邮件,请勿回复本邮件功能~\n\n 祝您工作愉快!', 'plain', 'utf-8')) |
30 | | - xlsxpart = MIMEApplication( |
| 23 | + msg['subject'] = header.Header('通知', 'utf-8') # 主题名称 |
| 24 | + msg.attach(text.MIMEText( |
| 25 | + '您好!\n这是一封测试邮件,使用Python实现自动发邮件,请勿回复本邮件功能~\n\n 祝您工作愉快!', 'plain', 'utf-8')) |
| 26 | + xlsxpart = application.MIMEApplication( |
31 | 27 | open(r'./data/email_test.xlsx', 'rb').read()) |
32 | 28 | xlsxpart.add_header('Content-Disposition', |
33 | 29 | 'attachment', filename='1.xlsx') |
|
0 commit comments