Problem: Python E-Mail attachment - Thunderbird

Job ID: 35322121

Budget: €8 – €30 EUR

Hi,

why is Thunderbird not including the attachment? Gmail and K9-Mail are working fine.
Please fix.
Budget only 8€.

Thanks a lot.

https://pastebin.com/t8eXyh7m

def send_error_email(err_subject, err_message, err_email, files=[], err_sender=error_sender):
logging.info(f'Sending error email to: {err_email}')
context = ssl.create_default_context()
with smtplib.SMTP_SSL(host, port, context=context) as server:
server.login(username, password)
message = MIMEMultipart("alternative")
message["Subject"] = err_subject
message["From"] = err_sender
message["To"] = err_email
text = err_message
html = f"""\
<html>
<body>
{err_message}
</body>
</html>
"""
part1 = MIMEText(text, "plain")
part2 = MIMEText(html, "html")
message.attach(part1)
message.attach(part2)

if files:
for file in files:
filepath = os.path.abspath(os.path.join(download_folder, file))
with open(filepath, 'rb') as attachment:
part = MIMEBase('application','pdf')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header(
"Content-Disposition",
f'attachment; filename="{file}"',
)
message.attach(part)

server.sendmail(err_sender, err_email, message.as_string())
Related categories: Python Email Developer