From 9efabf636706be829103dc604a1f94896094f4e4 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Wed, 31 Jul 2024 09:04:35 +0200 Subject: [PATCH] found the bremen_calling_logo.png file within the client's resources. Mapping towards that file when creating email notifications. This alleviates an additional dependency. --- src/server/BreCal/services/email_handling.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server/BreCal/services/email_handling.py b/src/server/BreCal/services/email_handling.py index dc13272..f091cf8 100644 --- a/src/server/BreCal/services/email_handling.py +++ b/src/server/BreCal/services/email_handling.py @@ -237,13 +237,20 @@ import typing from email.mime.application import MIMEApplication import mimetypes -def add_bremen_calling_logo(msg_multipart, path): +def add_bremen_calling_logo(msg_multipart): """ The image is not attached automatically when it is embedded to the content. To circumvent this, one commonly creates attachments, which are referred to in the email content. The content body refers to 'LogoBremenCalling', which the 'Content-ID' of the logo is assigned as. """ + # find the path towards the logo file (located at 'brecal\src\BreCalClient\Resources\logo_bremen_calling.png') + src_root_folder = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + resource_root_folder = os.path.join(src_root_folder, "BreCalClient", "Resources") + + path = os.path.join(resource_root_folder, "logo_bremen_calling.png") + assert os.path.exists(path), f"cannot find logo of bremen calling at path: {os.path.abspath(path)}" + with open(path, 'rb') as file: attachment = MIMEApplication(file.read(), _subtype=mimetypes.MimeTypes().guess_type(path), Name="bremen_calling.png") @@ -283,7 +290,7 @@ def create_shipcall_evaluation_notification(email_handler, ship_name:str, evalua email_handler.attach_file(path, msg=msg_multipart) # add the bremen calling logo, which is referred to in the email body - msg_multipart = add_bremen_calling_logo(msg_multipart, path=os.path.join("C:/Users/User/brecal/misc/logo_bremen_calling.png")) + msg_multipart = add_bremen_calling_logo(msg_multipart) return (msg_multipart,content) def send_notification(email_handler, email_tgts, msg, pwd, debug=False):