|  | @@ -1,4 +1,5 @@
 | 
											
												
													
														|  |  from dataclasses import dataclass
 |  |  from dataclasses import dataclass
 | 
											
												
													
														|  | 
 |  | +from pathlib import Path
 | 
											
												
													
														|  |  import smtplib
 |  |  import smtplib
 | 
											
												
													
														|  |  import ssl
 |  |  import ssl
 | 
											
												
													
														|  |  from email.mime.text import MIMEText
 |  |  from email.mime.text import MIMEText
 | 
											
										
											
												
													
														|  | @@ -17,16 +18,13 @@ class Message:
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  class SMTP_365:
 |  |  class SMTP_365:
 | 
											
												
													
														|  | -    def __init__(self, host='', port=0, local_hostname=None,
 |  | 
 | 
											
												
													
														|  | -                 timeout=30,
 |  | 
 | 
											
												
													
														|  | -                 source_address=None):
 |  | 
 | 
											
												
													
														|  | 
 |  | +    def __init__(self, host="", port=0, local_hostname=None, timeout=30, source_address=None):
 | 
											
												
													
														|  |          pass
 |  |          pass
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def login(self, user, password, *, initial_response_ok=True):
 |  |      def login(self, user, password, *, initial_response_ok=True):
 | 
											
												
													
														|  |          pass
 |  |          pass
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    def sendmail(self, from_addr, to_addrs, msg, mail_options=(),
 |  | 
 | 
											
												
													
														|  | -                 rcpt_options=()):
 |  | 
 | 
											
												
													
														|  | 
 |  | +    def sendmail(self, from_addr, to_addrs, msg, mail_options=(), rcpt_options=()):
 | 
											
												
													
														|  |          pass
 |  |          pass
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -38,18 +36,18 @@ class mail:
 | 
											
												
													
														|  |          if cfg is None:
 |  |          if cfg is None:
 | 
											
												
													
														|  |              self.cfg = config.Config()
 |  |              self.cfg = config.Config()
 | 
											
												
													
														|  |          self.mail_cfg = self.cfg.smtp
 |  |          self.mail_cfg = self.cfg.smtp
 | 
											
												
													
														|  | -        self.reply_to = self.cfg.kunde_safe + '@global-cube.com'
 |  | 
 | 
											
												
													
														|  | 
 |  | +        self.reply_to = self.cfg.kunde_safe + "@global-cube.com"
 | 
											
												
													
														|  |          self.context = ssl.create_default_context()
 |  |          self.context = ssl.create_default_context()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def __enter__(self):
 |  |      def __enter__(self):
 | 
											
												
													
														|  |          try:
 |  |          try:
 | 
											
												
													
														|  | -            if self.mail_cfg.secure == 'ssl':
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if self.mail_cfg.secure == "ssl":
 | 
											
												
													
														|  |                  self.mailserver = smtplib.SMTP_SSL(self.mail_cfg.server, self.mail_cfg.port, context=self.context)
 |  |                  self.mailserver = smtplib.SMTP_SSL(self.mail_cfg.server, self.mail_cfg.port, context=self.context)
 | 
											
												
													
														|  |              else:
 |  |              else:
 | 
											
												
													
														|  |                  self.mailserver = smtplib.SMTP(self.mail_cfg.server, self.mail_cfg.port)
 |  |                  self.mailserver = smtplib.SMTP(self.mail_cfg.server, self.mail_cfg.port)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              # self.mailserver.set_debuglevel(1)
 |  |              # self.mailserver.set_debuglevel(1)
 | 
											
												
													
														|  | -            if self.mail_cfg.secure == 'tls':
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if self.mail_cfg.secure == "tls":
 | 
											
												
													
														|  |                  # self.context.options |= ssl.OP_NO_TLSv1_2 | ssl.OP_NO_TLSv1_3
 |  |                  # self.context.options |= ssl.OP_NO_TLSv1_2 | ssl.OP_NO_TLSv1_3
 | 
											
												
													
														|  |                  self.context.minimum_version = ssl.TLSVersion["TLSv1_2"]
 |  |                  self.context.minimum_version = ssl.TLSVersion["TLSv1_2"]
 | 
											
												
													
														|  |                  self.mailserver.ehlo()
 |  |                  self.mailserver.ehlo()
 | 
											
										
											
												
													
														|  | @@ -68,37 +66,48 @@ class mail:
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def send(self, mailto, subject, html, attachment=None):
 |  |      def send(self, mailto, subject, html, attachment=None):
 | 
											
												
													
														|  |          msg = self.message(mailto, subject, html, attachment)
 |  |          msg = self.message(mailto, subject, html, attachment)
 | 
											
												
													
														|  | -        msg['Message-ID'] = make_msgid(domain=self.mail_cfg.server)
 |  | 
 | 
											
												
													
														|  | -        res = {'id': msg['Message-ID'], 'mailto': mailto, 'status': 'OK'}
 |  | 
 | 
											
												
													
														|  | 
 |  | +        msg["Message-ID"] = make_msgid(domain=self.mail_cfg.server)
 | 
											
												
													
														|  | 
 |  | +        res = {"id": msg["Message-ID"], "mailto": mailto, "status": "OK"}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          try:
 |  |          try:
 | 
											
												
													
														|  |              result = self.mailserver.sendmail(self.mail_cfg.email, mailto, msg.as_string())
 |  |              result = self.mailserver.sendmail(self.mail_cfg.email, mailto, msg.as_string())
 | 
											
												
													
														|  | -            with open('mail.txt', 'w') as fwh:
 |  | 
 | 
											
												
													
														|  | 
 |  | +            with open("mail.txt", "w") as fwh:
 | 
											
												
													
														|  |                  fwh.write(msg.as_string())
 |  |                  fwh.write(msg.as_string())
 | 
											
												
													
														|  |          except smtplib.SMTPException as e:
 |  |          except smtplib.SMTPException as e:
 | 
											
												
													
														|  |              print(e)
 |  |              print(e)
 | 
											
												
													
														|  |              pass
 |  |              pass
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def message(self, mailto, subject, html, attachment):
 |  |      def message(self, mailto, subject, html, attachment):
 | 
											
												
													
														|  | -        msg = MIMEMultipart('alternative')
 |  | 
 | 
											
												
													
														|  | -        msg['From'] = self.mail_cfg.email
 |  | 
 | 
											
												
													
														|  | -        msg['To'] = mailto
 |  | 
 | 
											
												
													
														|  | 
 |  | +        msg = MIMEMultipart("alternative")
 | 
											
												
													
														|  | 
 |  | +        msg["From"] = self.mail_cfg.email
 | 
											
												
													
														|  | 
 |  | +        msg["To"] = mailto
 | 
											
												
													
														|  |          # msg['Reply-To'] = self.reply_to
 |  |          # msg['Reply-To'] = self.reply_to
 | 
											
												
													
														|  | -        msg['Subject'] = subject
 |  | 
 | 
											
												
													
														|  | 
 |  | +        msg["Subject"] = subject
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          # text = '\n'.join([x for x, _ in attachment])
 |  |          # text = '\n'.join([x for x, _ in attachment])
 | 
											
												
													
														|  |          # msg.attach(MIMEText(text, 'plain'))
 |  |          # msg.attach(MIMEText(text, 'plain'))
 | 
											
												
													
														|  | -        msg.attach(MIMEText(html, 'html'))
 |  | 
 | 
											
												
													
														|  | 
 |  | +        msg.attach(MIMEText(html, "html"))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          for name, filename in attachment or []:
 |  |          for name, filename in attachment or []:
 | 
											
												
													
														|  |              with open(filename, "rb") as f:
 |  |              with open(filename, "rb") as f:
 | 
											
												
													
														|  |                  part = MIMEApplication(f.read(), Name=name)
 |  |                  part = MIMEApplication(f.read(), Name=name)
 | 
											
												
													
														|  | -                part['Content-Disposition'] = f'attachment; filename="{name}"'
 |  | 
 | 
											
												
													
														|  | 
 |  | +                part["Content-Disposition"] = f'attachment; filename="{name}"'
 | 
											
												
													
														|  |                  msg.attach(part)
 |  |                  msg.attach(part)
 | 
											
												
													
														|  |          return msg
 |  |          return msg
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -if __name__ == '__main__':
 |  | 
 | 
											
												
													
														|  | 
 |  | +if __name__ == "__main__":
 | 
											
												
													
														|  | 
 |  | +    base_dir = str(Path(__file__).parent)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      with mail() as m:
 |  |      with mail() as m:
 | 
											
												
													
														|  | -        m.send('robert.bedner@gmail.com', 'Test 123', 'kein Kommentar',
 |  | 
 | 
											
												
													
														|  | -               [('Umsatz_Bruttoertrag_Aftersales.pdf', '/home/robert/projekte/python/Portal/Publish/daten/gaps_vers_tag/Umsatz_Bruttoertrag_Aftersales_0.pdf')])
 |  | 
 | 
											
												
													
														|  | 
 |  | +        m.send(
 | 
											
												
													
														|  | 
 |  | +            "robert.bedner@gmail.com",
 | 
											
												
													
														|  | 
 |  | +            "Test 123",
 | 
											
												
													
														|  | 
 |  | +            "kein Kommentar",
 | 
											
												
													
														|  | 
 |  | +            [
 | 
											
												
													
														|  | 
 |  | +                (
 | 
											
												
													
														|  | 
 |  | +                    "Umsatz_Bruttoertrag_Aftersales.pdf",
 | 
											
												
													
														|  | 
 |  | +                    base_dir + "/Portal/Publish/daten/gaps_vers_tag/Umsatz_Bruttoertrag_Aftersales_0.pdf",
 | 
											
												
													
														|  | 
 |  | +                )
 | 
											
												
													
														|  | 
 |  | +            ],
 | 
											
												
													
														|  | 
 |  | +        )
 |