當前位置: 首頁>>代碼示例>>Python>>正文


Python smtplib.SMTPDataError方法代碼示例

本文整理匯總了Python中smtplib.SMTPDataError方法的典型用法代碼示例。如果您正苦於以下問題:Python smtplib.SMTPDataError方法的具體用法?Python smtplib.SMTPDataError怎麽用?Python smtplib.SMTPDataError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在smtplib的用法示例。


在下文中一共展示了smtplib.SMTPDataError方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: data

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def data(self, msg):
        """SMTP 'DATA' command -- sends message data to server. """

        (code, repl) = yield self.docmd(b"data")

        if code != 354:
            raise smtplib.SMTPDataError(code, repl)
        else:
            if isinstance(msg, str):
                msg = smtplib._fix_eols(msg).encode('ascii')
            q = smtplib._quote_periods(msg)
            if q[-2:] != CRLF:
                q = q + CRLF
            q = q + b"." + CRLF
            #self.send(q)
            yield self.send(q)
            (code, msg) = yield self.getreply()
            return (code, msg) 
開發者ID:vuamitom,項目名稱:tornado-smtpclient,代碼行數:20,代碼來源:client.py

示例2: test_fallimento_data

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def test_fallimento_data(self, mock_smtp):
        """
        In caso di fallimento durante il comando data  il messaggio viene rimesso in coda,
        tranne che in caso di errore 5XX che è permanente
        """
        codici = (451, 554, 500, 501, 503, 421, 552, 451, 452)
        for codice in codici:
            msg = 'code {}'.format(codice)
            instance = mock_smtp.return_value
            instance.sendmail.side_effect = smtplib.SMTPDataError(code=codice, msg=msg)
            self._invia_msg_singolo()
            if codice == 501:
                self.assertEqual(Messaggio.in_coda().count(), 0)
            else:
                self.assertEqual(Messaggio.in_coda().count(), 1)
            self._reset_coda() 
開發者ID:CroceRossaItaliana,項目名稱:jorvik,代碼行數:18,代碼來源:tests.py

示例3: send_mail

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def send_mail(subject, body, config=None):
    try:
        send_mail_main(subject, body, config=config)
    except smtplib.SMTPDataError:
        pass  # ignore email errors 
開發者ID:EdwardBetts,項目名稱:osm-wikidata,代碼行數:7,代碼來源:mail.py

示例4: test_421_from_data_cmd

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def test_421_from_data_cmd(self):
        class MySimSMTPChannel(SimSMTPChannel):
            def found_terminator(self):
                if self.smtp_state == self.DATA:
                    self.push('421 closing')
                else:
                    super().found_terminator()
        self.serv.channel_class = MySimSMTPChannel
        smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
        smtp.noop()
        with self.assertRaises(smtplib.SMTPDataError):
            smtp.sendmail('John@foo.org', ['Sally@foo.org'], 'test message')
        self.assertIsNone(smtp.sock)
        self.assertEqual(self.serv._SMTPchannel.rcpt_count, 0) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_smtplib.py

示例5: send_message

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def send_message(mailfrom, rcptto, data):
    try:
        server = smtplib.SMTP(MX, 25, PHISH_MX)
        server.sendmail(mailfrom, rcptto, data)

    except smtplib.SMTPDataError as e:
        print '[-] {0}'.format(str(e[1]))

    except smtplib.SMTPServerDisconnected as e:
        print '[-] {0}'.format(str(e))

    except smtplib.SMTPConnectError as e:
        print '[-] {0}'.format(str(e[1])) 
開發者ID:averagesecurityguy,項目名稱:Phishing,代碼行數:15,代碼來源:sendphish.py

示例6: quota_exceeded

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def quota_exceeded(patch_token_manager, monkeypatch, request):
    monkeypatch.setattr('inbox.sendmail.smtp.postel.SMTPConnection',
                        erring_smtp_connection(
                            smtplib.SMTPDataError, 550,
                            request.param)) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:7,代碼來源:test_sending.py

示例7: insecure_content

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def insecure_content(patch_token_manager, monkeypatch):
    monkeypatch.setattr(
        'inbox.sendmail.smtp.postel.SMTPConnection',
        erring_smtp_connection(
            smtplib.SMTPDataError, 552,
            '5.7.0 This message was blocked because its content presents a '
            'potential\\n5.7.0 security issue.')) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:9,代碼來源:test_sending.py

示例8: send_sms

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def send_sms(message_text, phone_number, carrier, from_address=None):
	"""
	Send an SMS message by emailing the carriers SMS gateway. This method
	requires no money however some networks are blocked by the carriers
	due to being flagged for spam which can cause issues.

	:param str message_text: The message to send.
	:param str phone_number: The phone number to send the SMS to.
	:param str carrier: The cellular carrier that the phone number belongs to.
	:param str from_address: The optional address to display in the 'from' field of the SMS.
	:return: This returns the status of the sent messsage.
	:rtype: bool
	"""
	from_address = (from_address or DEFAULT_FROM_ADDRESS)
	phone_number = phone_number.replace('-', '').replace(' ', '')
	# remove the country code for these 10-digit based
	match = re.match('1?(?P<phone_number>[0-9]{10})', phone_number)
	if match is None:
		raise ValueError('the phone number appears invalid')
	phone_number = match.group('phone_number')

	if len(message_text) > 160:
		raise ValueError('message length exceeds 160 characters')
	message = MIMEText(message_text)

	carrier_address = lookup_carrier_gateway(carrier)
	if not carrier_address:
		raise ValueError('unknown carrier specified')

	to_address = "{0}@{1}".format(phone_number, carrier_address)
	message['To'] = to_address
	message['From'] = from_address

	sms_gateways = get_smtp_servers(carrier_address)
	random.shuffle(sms_gateways)
	message_sent = False
	for sms_gateway in sms_gateways:
		try:
			smtp_connection = smtplib.SMTP(sms_gateway)
			smtp_connection.sendmail(from_address, [to_address], message.as_string())
			smtp_connection.quit()
		except (smtplib.SMTPConnectError, smtplib.SMTPDataError, smtplib.SMTPHeloError):
			continue
		message_sent = True
		break
	return message_sent 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:48,代碼來源:sms.py

示例9: deliver_testcase

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def deliver_testcase(self, testcase, recipient):
        super().deliver_testcase(testcase, recipient)
        print("Sending test case {} from test '{}' to {}".format(self.testcase_index, self.testcases.name, recipient))
        self.allow_delay_increase()
        try:
            try:
                if testcase.delivery_sender:
                    sender = self.sender
                else:
                    sender = None
            except AttributeError:
                sender = None

            try:
                if testcase.delivery_recipient:
                    recipient = recipient
                else:
                    recipient = None
            except AttributeError:
                recipient = None

            result = self.smtp.send_message(testcase, sender, recipient)
            if result:
                for failed_recipient, (code, message) in result.items():
                    print("! Sending to recipient {} failed with error code {}: {}".format(failed_recipient, code, message))
                    self.logger.log(self.testcases.identifier, self.testcase_index, self.recipient, False, code, message)
                    if code in self.delay_increasing_status:
                        self.increase_delay()
            else:
                self.logger.log(self.testcases.identifier, self.testcase_index, self.recipient)
        except smtplib.SMTPRecipientsRefused as e:
            print("! Reciepent refused")
            for failed_recipient, (code, message) in e.recipients.items():
                print("! Sending to recipient {} failed with error code {}: {}".format(failed_recipient, code, str(message, "iso-8859-1")))
                self.logger.log(self.testcases.identifier, self.testcase_index, failed_recipient, False, code, str(message, "iso-8859-1"))
                if code in self.delay_increasing_status:
                    self.increase_delay()
        except smtplib.SMTPHeloError as e:
            print("! SMTP error while HELO: " + str(e))
            if e.smtp_code in self.delay_increasing_status:
                self.increase_delay()
        except smtplib.SMTPSenderRefused as e:
            print("! SMTP server rejected sender address: " + str(e))
            self.logger.log(self.testcases.identifier, self.testcase_index, self.recipient, False, e.smtp_code, e.smtp_error)
            if e.smtp_code in self.delay_increasing_status:
                self.increase_delay()
        except smtplib.SMTPDataError as e:
            print("! Unexpected SMTP error: " + str(e))
            self.logger.log(self.testcases.identifier, self.testcase_index, self.recipient, False, e.smtp_code, e.smtp_error)
            if e.smtp_code in self.delay_increasing_status:
                self.increase_delay()
        except smtplib.SMTPNotSupportedError as e:
            print("! SMTP server doesn't supports: " + str(e))
            self.logger.log(self.testcases.identifier, self.testcase_index, self.recipient, False, -1, str(e))
        except smtplib.SMTPServerDisconnected as e:
            self.logger.log(self.testcases.identifier, self.testcase_index, self.recipient, False, -2, str(e))
            print("! SMTP server disconnected unexpected - reconnecting: " + str(e))
            self.smtp = smtplib.SMTP(self.target) 
開發者ID:TKCERT,項目名稱:mail-security-tester,代碼行數:60,代碼來源:delivery.py

示例10: sendmail

# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPDataError [as 別名]
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
                 rcpt_options=[]):

        yield self.ehlo_or_helo_if_needed()
        esmtp_opts = []
        if isinstance(msg, str):
            msg = smtplib._fix_eols(msg).encode('ascii')
        if self.does_esmtp:

            if self.has_extn('size'):
                esmtp_opts.append("size=%d" % len(msg))
            for option in mail_options:
                esmtp_opts.append(option)

        (code, resp) = yield self.mail(from_addr, esmtp_opts)
        if code != 250:
            if code == 421:
                self.close()
            else:
                yield self._rset()
            raise smtplib.SMTPSenderRefused(code, resp, from_addr)
        senderrs = {}
        if isinstance(to_addrs, str):
            to_addrs = [to_addrs]
        for each in to_addrs:
            (code, resp) = yield self.rcpt(each, rcpt_options)
            if (code != 250) and (code != 251):
                senderrs[each] = (code, resp)
            if code == 421:
                self.close()
                raise smtplib.SMTPRecipientsRefused(senderrs)
        if len(senderrs) == len(to_addrs):
            # the server refused all our recipients
            yield self._rset()
            raise smtplib.SMTPRecipientsRefused(senderrs)
        (code, resp) =  yield self.data(msg)
        if code != 250:
            if code == 421:
                self.close()
            else:
                yield self._rset()
            raise smtplib.SMTPDataError(code, resp)
        #if we got here then somebody got our mail
        return senderrs 
開發者ID:vuamitom,項目名稱:tornado-smtpclient,代碼行數:46,代碼來源:client.py


注:本文中的smtplib.SMTPDataError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。