|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from email.header import Header #处理邮件主题
from email.mime.text import MIMEText # 处理邮件内容
from email.utils import parseaddr, formataddr #用于构造特定格式的收发邮件地址
import smtplib #用于发送邮件
start = datetime.datetime.now()
print(start)
winsound.PlaySound('Windows Foreground.wav', flags=1)
wb = openpyxl.load_workbook('D:/04/april_08_133.xlsx')#表格读取
sheet = wb.get_sheet_by_name('qq')
#email = list(mo7)#转换为列表
def _format_addr(s):
name, addr = parseaddr(s)#和前面名字变量相同,测试没问题
return formataddr((Header(name, 'utf-8').encode(), addr))
n = 1
while n<3:
name = sheet['A' + str(n+1)].value
email = sheet['M' + str(n+1)].value
#邮箱切换
#from_addr = '**@163.com';password = **'
from_addr = '12**@qq.com';password = '**'
#to_addrs = ['1218100502@qq.com']加 上不行,放到下行放一起也不行。只是为了测试
to_addrs = email #这里存放批量的邮件地址,或者我们也可以从本地存放邮件地址的文件中读取.(,'1218100502@qq.com')多个隔开可批量发。要用列表好办
smtp_server = 'smtp.163.com'#
msg = MIMEText('案件通知--' + name + ',6 雷专员', 'plain','utf-8')
msg['From'] = _format_addr('法务部<%s>'%from_addr)
msg['Subject'] = Header('紧急通知--' + name,'utf-8').encode()##
server = smtplib.SMTP(smtp_server,25)
server.login(from_addr, password)
for to_addr in to_addrs:
msg['To'] = _format_addr('接收<%s>'%to_addr)
try:
server.sendmail(from_addr, to_addr, msg.as_string())
except:
print('发送失败,再次尝试')#可配上其他声音
winsound.Beep(1000,700)
server.sendmail(from_addr, to_addr, msg.as_string())
print('发送邮件到'+to_addr)
print(name)
winsound.PlaySound('Windows Foreground.wav', flags=1)
#winsound.Beep(2000,1500)
n+=1
server.quit() |
|