diff --git a/mylib/report.py b/mylib/report.py index dd44309..ec3d676 100644 --- a/mylib/report.py +++ b/mylib/report.py @@ -33,6 +33,8 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance def __init__(self, email_client=None, initialize=True, **kwargs): super().__init__(**kwargs) self.email_client = email_client + self._attachment_files = [] + self._attachment_payloads = [] if initialize: self.initialize() @@ -84,6 +86,14 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance """ Read the report content """ return "".join(self.content) + def add_attachment_file(self, filepath): + """ Add attachment file """ + self._attachment_files.append(filepath) + + def add_attachment_payload(self, payload): + """ Add attachment payload """ + self._attachment_payloads.append(payload) + def send(self, subject=None, rcpt_to=None, email_client=None, just_try=False): """ Send report using an EmailClient """ if rcpt_to is None: @@ -102,7 +112,10 @@ class Report(ConfigurableObject): # pylint: disable=useless-object-inheritance if not content: log.debug('Report is empty, do not send it') return True - msg = email_client.forge_message(rcpt_to, subject=subject, text_body=content) + msg = email_client.forge_message( + rcpt_to, subject=subject, text_body=content, + attachment_files=self._attachment_files, + attachment_payloads=self._attachment_payloads) if email_client.send(rcpt_to, msg=msg, just_try=just_try): log.debug('Report sent to %s', rcpt_to) return True