python类SMTPResponseException()的实例源码

main.py 文件源码 项目:TwitterStockMonitor 作者: semaaJ 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def email(handle, matches):
    """Emails a list of people"""

    company_output = ', '.join([comp.upper() for comp in matches])

    try:
        with open('./Files/emails.txt') as f:
            email_list = f.read().split()

        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(EMAIL, PASSWORD)
        server.sendmail(EMAIL, email_list,
                        f'{handle} just tweeted about {company_output}. '
                        f'Might be time to check your shares...')
        server.quit()

    except smtplib.SMTPResponseException as error:
        logging.debug(error)
test_smtplib.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def testLineTooLong(self):
        self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP,
                          HOST, self.port, 'localhost', 3)
test_smtplib.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def testLineTooLong(self):
        self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP,
                          HOST, self.port, 'localhost', 3)
test_smtplib.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_with_statement_QUIT_failure(self):
        with self.assertRaises(smtplib.SMTPResponseException) as error:
            with smtplib.SMTP(HOST, self.port) as smtp:
                smtp.noop()
                self.serv._SMTPchannel.quit_response = '421 QUIT FAILED'
        self.assertEqual(error.exception.smtp_code, 421)
        self.assertEqual(error.exception.smtp_error, b'QUIT FAILED')

    #TODO: add tests for correct AUTH method fallback now that the
    #test infrastructure can support it.

    # Issue 5713: make sure close, not rset, is called if we get a 421 error
test_smtplib.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def testLineTooLong(self):
        self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP,
                          HOST, self.port, 'localhost', 3)
test_smtplib.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def testLineTooLong(self):
        self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP,
                          HOST, self.port, 'localhost', 3)
test_smtplib.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_with_statement_QUIT_failure(self):
        with self.assertRaises(smtplib.SMTPResponseException) as error:
            with smtplib.SMTP(HOST, self.port) as smtp:
                smtp.noop()
                self.serv._SMTPchannel.quit_response = '421 QUIT FAILED'
        self.assertEqual(error.exception.smtp_code, 421)
        self.assertEqual(error.exception.smtp_error, b'QUIT FAILED')

    #TODO: add tests for correct AUTH method fallback now that the
    #test infrastructure can support it.

    # Issue 17498: make sure _rset does not raise SMTPServerDisconnected exception
contact_form.py 文件源码 项目:django-basic 作者: igor-chepurnoi 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def contact(self):
        subject = self.cleaned_data['subject']
        from_email = self.cleaned_data['email']
        message = self.cleaned_data['body']

        try:
            return send_mail(subject, message, from_email, settings.ADMINS)
        except SMTPResponseException:
            return False
mail.py 文件源码 项目:timestrap 作者: overshard 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def send_messages(self, email_messages):
        """
        Override the from_email property all email messages.
        """
        if not email_messages:
            return
        with self._lock:
            for message in email_messages:
                message.from_email = get_site_setting('smtp_from_address')
        try:
            super(EmailBackend, self).send_messages(email_messages)
        except (SMTPResponseException, socket_error) as e:
            # TODO: Determine how to handle failures gracefully.
            raise e
test_smtplib.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def testLineTooLong(self):
        self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP,
                          HOST, self.port, 'localhost', 3)
test_smtplib.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_with_statement_QUIT_failure(self):
        with self.assertRaises(smtplib.SMTPResponseException) as error:
            with smtplib.SMTP(HOST, self.port) as smtp:
                smtp.noop()
                self.serv._SMTPchannel.quit_response = '421 QUIT FAILED'
        self.assertEqual(error.exception.smtp_code, 421)
        self.assertEqual(error.exception.smtp_error, b'QUIT FAILED')

    #TODO: add tests for correct AUTH method fallback now that the
    #test infrastructure can support it.

    # Issue 17498: make sure _rset does not raise SMTPServerDisconnected exception
utils.py 文件源码 项目:authserver 作者: jdelic 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def sendmail(self, from_addr: str, to_addrs: Sequence[str], msg: bytes, mail_options: List[str]=[],
                 rcpt_options: List[str]=[]) -> Union[str, None]:
        """
        Wraps smtplib.sendmail and handles all the exceptions it can throw.
        :return: a SMTP return string or None
        """
        with smtplib.SMTP(self.external_ip, self.external_port) as smtp:
            try:
                smtp.sendmail(from_addr, to_addrs, msg, mail_options, rcpt_options)
            except smtplib.SMTPSenderRefused as e:
                if isinstance(e.smtp_error, bytes):
                    errorstr = e.smtp_error.decode("utf-8", errors="ignore")
                else:
                    errorstr = str(e.smtp_error)
                _log.info("Downstream server refused sender: %s (%s %s)", e.sender, e.smtp_code, errorstr)
                return "%s %s" % (e.smtp_code, e.smtp_error)
            except smtplib.SMTPResponseException as e:
                # This exception baseclass is for all exceptions that have a SMTP response code.
                # Return the downstream error code upstream
                if isinstance(e.smtp_error, bytes):
                    errorstr = e.smtp_error.decode("utf-8", errors="ignore")
                else:
                    errorstr = str(e.smtp_error)
                _log.info("Unexpected response from server (passed upstream): %s %s", e.smtp_code, errorstr)
                return "%s %s" % (e.smtp_code, errorstr)
            except smtplib.SMTPRecipientsRefused as e:
                _log.info("Some recipients where refused by the downstream server: %s", ", ".join(e.recipients.keys()))
                if self.internal_ip and self.internal_port:
                    with smtplib.SMTP(self.internal_ip, self.internal_port) as smtp_r:
                        try:
                            smtp_r.sendmail(
                                "<>",
                                [from_addr],
                                self._format_denied_recipients(msg, list(e.recipients.keys()))
                            )
                        except smtplib.SMTPException as ex:
                            _log.exception("Error while sending denied recipients reply: %s", str(ex))
                return None
            except smtplib.SMTPServerDisconnected as e:
                _log.info("Downstream server unexpectedly disconnected: %s", str(e))
                return "421 Possible network problem. Please try again."
            return None


# patch the SMTP channel implementation to pass us a reference to the channel
# and use sane logging


问题


面经


文章

微信
公众号

扫码关注公众号