def _message_send(self: Any, connection: flask_mail.Connection) -> None: """Send a single message instance. If TESTING is True the message will not actually be sent. :param self: a Message instance. """ sender = current_app.config["MAIL_SENDER"] if not self.extra_headers: self.extra_headers = {} self.extra_headers["Sender"] = sender connection.send(self, sender)
def test_configure_host_tls_failure(self): with mock.patch('flask_mail.smtplib.SMTP') as MockSMTP: mock_host = MockSMTP.return_value mock_host.starttls.return_value = (501, "Syntax error (testing)") with mock.patch.object(self.mail, "use_tls", True): self.assertTrue(self.mail.use_tls) self.assertRaises(smtplib.SMTPResponseException, Connection(self.mail).configure_host)
def send(self, connection: Connection = None): type(self).check_limit() msg = self.message try: if connection is not None: connection.send(msg) else: mail.send(msg) self.sent_at = dt.datetime.utcnow() db.session.commit() except (SMTPDataError, SMTPSenderRefused, SMTPRecipientsRefused) as e: self.sent_at = dt.datetime.utcnow() self.error = str(e) db.session.commit() except Exception as e: db.session.rollback() raise e