当前位置: 首页>>代码示例>>Python>>正文


Python smtplib.SMTPHeloError方法代码示例

本文整理汇总了Python中smtplib.SMTPHeloError方法的典型用法代码示例。如果您正苦于以下问题:Python smtplib.SMTPHeloError方法的具体用法?Python smtplib.SMTPHeloError怎么用?Python smtplib.SMTPHeloError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smtplib的用法示例。


在下文中一共展示了smtplib.SMTPHeloError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fallimento_helo

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPHeloError [as 别名]
def test_fallimento_helo(self, mock_smtp):
        """
        In caso di fallimento durante helo il messaggio viene rimesso in coda, tranne che in caso
        di errore 5XX che è permanente
        """
        self.assertEqual(Messaggio.in_coda().count(), 0)
        codici = (500, 501, 504, 521, 421)
        for codice in codici:
            msg = 'code {}'.format(codice)
            instance = mock_smtp.return_value
            instance.sendmail.side_effect = smtplib.SMTPHeloError(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,代码行数:19,代码来源:tests.py

示例2: __ehlo

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPHeloError [as 别名]
def __ehlo(self):
        try:
            self.server.ehlo()
            if not self.server.does_esmtp:
                logger.error('The server does not support ESMTP')
                exit(1)
        except smtplib.SMTPHeloError:
            logger.error('The server did not reply properly to the EHLO/HELO greeting.')
            exit(1) 
开发者ID:mikechabot,项目名称:smtp-email-spoofer-py,代码行数:11,代码来源:smtpconnection.py

示例3: send_sms

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPHeloError [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

示例4: deliver_testcase

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPHeloError [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


注:本文中的smtplib.SMTPHeloError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。