使用 python 的 Excel 电子邮件附件

问题描述 投票:0回答:0

需要在outlook邮件中附加excel文件。我也需要使用用户名和密码。

得到错误 excel_file=r'D:\HL\EWS\Pilot TN1 TN3 Project\PILOT AUTOMATED RUNS\Digital_Agreements_'+str(current_date)+'.xlsx'

def send_mail_with_excel(recipient_email, subject, content, excel_file): `msg = EmailMessage() msg['主题'] = 主题 msg['发件人'] = SENDER_EMAIL msg['To'] = recipient_email msg.set_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 smtplib.SMTP_SSL('smtp-mail.outlook.com', 587) as smtp:
    smtp.login(SENDER_EMAIL, APP_PASSWORD)
    smtp.send_message(msg)
`    
    

send_mail_with_excel(recipient_email, subject, content, excel_file)

错误: 在 send_mail_with_excel 中输入 In [78] 用 open(excel_file, 'rb') 作为 f:

TypeError:需要一个整数(得到类型 str)

python excel email email-attachments
© www.soinside.com 2019 - 2024. All rights reserved.