msg['To']=receiver_email msg['Subject']='Excel文件'# 添加Excel文件作为附件withopen('data.xlsx','rb')asfile:attachment=MIMEApplication(file.read(),_subtype='xlsx')attachment.add_header('Content-Disposition','attachment',filename='data.xlsx')msg.attach(attachment)# 发送邮件withsmtplib.SMTP(smt...
att1["Content-Disposition"] ='attachment; filename="1.xlsx"'message.attach(att1)try: smtpObj=smtplib.SMTP() smtpObj.connect(mail_host,25) #25为 SMTP 端口号 smtpObj.login(mail_user,mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) print ("邮件发送成功") except smtplib...
keys = [['1','小明','21'],['2','小红','19']] #定义需要写进表中得值 def Excel(keys): book = xlwt.Workbook(encoding='utf-8',style_compression=0) #创建excel表格类型文件 这里是’utf-8’的形式,style_compression设置是否压缩,不是很常用,赋值为0表示不压缩。 sheet = book.add_sheet('...
xlsxpart.add_header('Content-Disposition','attachment', filename=xlsxFile)### 生成第二个文件 End ###send_mail(mail_msg)exceptException as e:printstr(Exception)printstr(e)#关闭游标cursor.close()#关闭数据库连接#db.close()### 生成第三个文件#使用cursor()方法获取操作游标cursor =db.cursor()#...
('Content-Disposition','attachment',filename=annex_name)message.attach(part1)returnmessagedefsend_email(sender,password,receivers,mail_host,message):smtpObj=smtplib.SMTP()smtpObj.connect(mail_host,25)smtpObj.login(mail_user,password)smtpObj.sendmail(sender,receivers,message.as_string())print('...
msg = EmailMessage() msg['Subject'] = subject msg['From'] = SENDER_EMAIL msg['To'] = recipient_email msg.set_content(content) with open(excel_file, 'rb') as f: file_data = f.read() msg.add_attachment(file_data, maintype="application", subtype="xlsx", filename=excel_file) with...
文件名file_path=os.path.join(file_name)# 文件路径xlsx=MIMEApplication(open(file_path,'rb').read())# 打开Excel,读取Excel文件xlsx["Content-Type"]='application/octet-stream'# 设置内容类型xlsx.add_header('Content-Disposition','attachment',filename=file_name)# 添加到header信息message.attach(xlsx...
smtp_server, 465)# H E L O 向服务器标识用户身份 smtp.helo(smtp_server)# 服务器返回结果确认 smtp.ehlo(smtp_server)# 登录邮箱服务器用户名和密码 smtp.login(user, password)print("Start send email...")smtp.sendmail(user, receives, msg_root.as_string())smtp.quit()print("Send End!")
file = "automate_report.pdf" # in the same directory as script password = "abc123"# Create the email head (sender, receiver, andsubject)email = MIMEMultipart() email["From"] = sender_email email["To"] = receiver_email email["Subject"] = subject# Add body and attachment toemailemail....
email_content = MIMEText(content, 'plain', 'utf-8') # 读取工作表文件数据 with open('./04_月考勤表.xlsx', 'rb') as f: file_data = f.read() # 设置内容类型为附件 attachment = MIMEText(file_data, 'base64', 'utf-8') # 设置附件标题以及文件类型 ...