A script for sending email with attachments is working, but all attachments, if any, are arriving as .eml files rather than as jpg, pdf, txt, etc. They do open correctly, but I would prefer that the bear their actual name and type. Although I’ve made minor changes for Python 3, it did work for me on Python 2.7.
Also, I keep coming across references that set_payload has been deprecated, but I can’t see what to use instead.
# Attach any files
files = '''/Users/Mine/Desktop/RKw.jpeg\n/Users/Mine/Desktop/PG_2022.pdf'''.splitlines()
for file in files:
attachment = open(file, "rb")
part = MIMEBase("application", "octet-stream")
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header("Content-Disposition", f"attachment; filename= {file.split('/')[-1]}")
msg.add_attachment(part)