Exemplo n.º 1
0
 def _quoted_message(self, e: Envelope):
     self.assertEqual(self.long_text, e.message())
     self.assertIn(
         self.long_text,
         e.preview())  # when using preview, we receive original text
     output = str(
         e.send(False))  # but when sending, quoted text is got instead
     self.assertNotIn(self.long_text, output)
     self.assertIn(self.quoted, output)
Exemplo n.º 2
0
    def _send_mail(self, envelope: Envelope) -> None:
        recipients = self._test_email_set if self._test_email_set else envelope.recipients

        Log.info("Sending email from {} to {}", envelope.from_(),
                 ", ".join(list(envelope.recipients())))
        if Log.level >= Log.DEBUG:
            formatted_mail = "\n".join(
                ["    > " + l for l in envelope.preview().splitlines()])
            Log.debug("Message content:\n" + formatted_mail)

        if not self._dry_run:
            # tls settings
            envelope.smtp(
                host=self._smtp["host"],
                port=self._smtp["port"],
                user=self._smtp["user"],
                password=self._smtp["password"],
                security=self._smtp["security"],
            )

            # sign the email
            if self._gpg_sign:
                envelope.signature(
                    key=self._gpg_key if self._gpg_key else True,
                    passphrase=self._gpg_passphrase)

            # encrypt the email
            if self._gpg_encrypt:
                envelope.encryption()

            # send the email
            try:
                envelope.send()
            except smtplib.SMTPAuthenticationError as err:
                raise Exception(
                    f"Authentication failed: {err.self._error.decode('utf-8')}"
                )
            except smtplib.SMTPServerDisconnected as err:
                raise Exception(
                    f"Server disconnected: {err.self._error.decode('utf-8')}")
            except Exception as e:
                raise e