I am struggling with sending email with the attachment of excel file by Python. The problem I am facing now is python change excel file format to '.aaf' format or other unknown formats. It happens when python sends excel files to specific email addresses, which I guess are intranet mail address. Other personal email addresses(e.g. gmail) have no trouble, no change in file format. The assuming-intranet mail addresses also receieve pdf file with awkward format as well as excel file. I am digging out any clue to solve it day and night, but can't find any advice related to it. Any help? Below is my code :
note) attachment = file path + file name
def send_mail(mail_list, cc_list, subject, text, attachment):
msg = EmailMessage()
msg["From"] = MY_ID
msg["To"] = ",".join(mail_list)
msg["Cc"] = ",".join(cc_list)
msg["Subject"] = subject
msg.set_content(text)
if attachment:
filename = Path(attachment).name
with open(filename, "rb") as f:
msg.add_attachment(f.read(), maintype="application", subtype="xlsx", filename=filename)
msg.add_header('Content-Disposition', 'attachment; filename='+filename)
with SMTP_SSL("smtp.gmail.com", 465) as smtp:
smtp.login(MY_ID, MY_PW)
smtp.send_message(msg)