From e3bb428c26c89e49393847907bd6ad24b412df11 Mon Sep 17 00:00:00 2001 From: Alfusainey Jallow Date: Tue, 27 Jun 2023 12:40:26 +0200 Subject: [PATCH] bug fix: close file after reading Signed-off-by: Alfusainey Jallow --- wo/core/sendmail.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wo/core/sendmail.py b/wo/core/sendmail.py index 9a60602..53fa3ff 100644 --- a/wo/core/sendmail.py +++ b/wo/core/sendmail.py @@ -17,9 +17,10 @@ def WOSendMail(send_from, send_to, subject, text, files, server="localhost", msg.attach(MIMEText(text)) - for f in files: + for file in files: part = MIMEBase('application', "octet-stream") - part.set_payload(open(f, "rb").read()) + with open(file, 'rb') as f: + part.set_payload(f.read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="{0}"' .format(os.path.basename(f)))