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


Python smtplib.SMTPConnectError方法代码示例

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


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

示例1: testFailingHELO

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def testFailingHELO(self):
        self.assertRaises(smtplib.SMTPConnectError, smtplib.SMTP,
                            HOST, self.port, 'localhost', 3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_smtplib.py

示例2: _send_smtp

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def _send_smtp(message, subject, to, to_name, sender, sender_name):
    """SMTP implementation of sending email."""
    host = app.config.get('MAIL_HOST')

    if not host:
        raise MailFailure('SMTP Server Not Configured')

    try:
        server = smtplib.SMTP(host)
    except (smtplib.SMTPConnectError, socket.error) as ex:
        app.logger.error('Unable to send mail: %s', str(ex))
        raise MailFailure('Error connecting to SMTP server.')

    msg = text.MIMEText(message)
    msg['Subject'] = subject
    msg['To'] = email.utils.formataddr((to_name, to))
    msg['From'] = email.utils.formataddr((sender_name, sender))

    try:
        if app.debug:
            server.set_debuglevel(True)
        server.sendmail(sender, [to], msg.as_string())
    except (smtplib.SMTPException, socket.error) as ex:
        app.logger.error('Unable to send mail: %s', str(ex))
        raise MailFailure('Error sending mail to SMTP server.')
    finally:
        try:
            server.quit()
        except smtplib.SMTPException:
            pass 
开发者ID:google,项目名称:ctfscoreboard,代码行数:32,代码来源:mail.py

示例3: send_message

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

示例4: test_fallimento_connect

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def test_fallimento_connect(self, mock_smtp):
        """
        In caso di fallimento durante il connect il messaggio viene rimesso in coda
        """
        codici = (421,)
        for codice in codici:
            msg = 'code {}'.format(codice)
            instance = mock_smtp.return_value
            instance.sendmail.side_effect = smtplib.SMTPConnectError(code=codice, msg=msg)
            self._invia_msg_singolo()
            self.assertEqual(Messaggio.in_coda().count(), 1)
            self._reset_coda() 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:14,代码来源:tests.py

示例5: validate_mx

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def validate_mx(server, domain):
    try:
        if server in MX_RECORD_CACHE:
            return MX_RECORD_CACHE[server]
        smtp = smtplib.SMTP(timeout=10)
        smtp.connect(server)
        status, _ = smtp.helo()
        if status != 250:
            smtp.quit()
            print("%s answer: %s - %s" % (server, status, _))
        smtp.mail('')
        status, _ = smtp.rcpt("invalid@"+domain)
        if status == 250:
            smtp.quit()
            MX_RECORD_CACHE[server] = True
            return True
        print("%s answer: %s - %s" % (server, status, _))
        smtp.quit()
    except smtplib.SMTPServerDisconnected as e:  # Server not permits verify user
        print("%s disconnected. [%s]" % (server, e))
    except smtplib.SMTPConnectError as e:
        print("Unable to connect to %s. [%s]" % (server, e))
    except socket.timeout as e:
        print("Timedout connecting to %s. [%s]" % (server, e))
    MX_RECORD_CACHE[server] = False
    return False        

# Lookup a domain and get its mailserver 
开发者ID:tatanus,项目名称:SPF,代码行数:30,代码来源:emails.py

示例6: send_sms

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

示例7: __init__

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def __init__(self,thread,starttime,opentrackurl,attach, sender , subject , message , *sendto ,**kwargs):


        al = Queue()

        smtp = kwargs['smtpt']
        mailhost = kwargs['mailhost']
        passwd = kwargs['passwd']
        port = kwargs['port']

        thr = int(thread)

        null = ""


        try:
            mail = smtplib.SMTP(smtp, port)
            mail.starttls()
            mail.login("{}".format(mailhost), '{}'.format(passwd))
            mail.quit()


            for i in range(thr):
                self.t = Thread(target=self.skeleton, args=(starttime,opentrackurl,attach,sender,message,subject, mailhost, passwd, smtp, int(port), al))
                self.t.daemon = True
                self.t.start()


            for mass in sendto:
                al.put(mass)

            al.join()

            os.startfile(os.getcwd() + '\\sleuth\\mailOpenList\\' + starttime + '.txt')

        except smtplib.SMTPAuthenticationError:
            print("Authentication Error", "Wrong Username or Password !", "Info")
            sys.stderr.flush()


        except smtplib.SMTPConnectError:
            print("Connection Error", "SMTP Server Down !", "Info")
            sys.stderr.flush()

        except smtplib.SMTPNotSupportedError:
            print("Support Error", "SMTP Not Supported !", "Info")
            sys.stderr.flush()

        except Exception as f:

            t, o, tb = sys.exc_info()
            print(f, tb.tb_lineno)
            sys.stderr.flush()

        #SendMail.skeleton(null,msg,mailhost,passwd,smtp,int(port),*sendto) 
开发者ID:azizaltuntas,项目名称:Camelishing,代码行数:57,代码来源:smtp.py

示例8: verify

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def verify(self, email):
        """
        method that performs the verification on the passed
        email address.
        """
        lookup = {
            'address': None,
            'valid_format': False,
            'deliverable': False,
            'full_inbox': False,
            'host_exists': False,
            'catch_all': False,
        }
        try:
            lookup['address'] = self._parse_address(email)
            lookup['valid_format'] = True
        except EmailFormatError:
            lookup['address'] = f"{email}"
            return lookup
        
        # look for mx record and create a list of mail exchanges
        try:
            mx_record = resolver.query(lookup['address'].domain, 'MX')
            mail_exchangers = [exchange.to_text().split() for exchange in mx_record]
            lookup['host_exists'] = True
        except (resolver.NoAnswer, resolver.NXDOMAIN, resolver.NoNameservers):
            lookup['host_exists'] = False
            return lookup

        for exchange in mail_exchangers:
            try:
                host_exists, deliverable, catch_all = self._can_deliver(exchange, lookup['address'])
                if deliverable:
                    lookup['host_exists'] = host_exists
                    lookup['deliverable'] = deliverable
                    lookup['catch_all'] = catch_all
                    break
            except SMTPRecepientException as err:
                # Error handlers return a dict that is then merged with 'lookup'
                kwargs = handle_error.get(err.code, handle_unrecognised)(err.response)
                # This expression merges the lookup dict with kwargs
                lookup = {**lookup, **kwargs}

            except smtplib.SMTPServerDisconnected as err:
                lookup['message'] = "Internal Error"
            except smtplib.SMTPConnectError as err:
                lookup['message'] = "Internal Error. Maybe blacklisted"

        return lookup 
开发者ID:Gardener-gg,项目名称:email-verifier,代码行数:51,代码来源:verifier.py

示例9: validate_email_address

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPConnectError [as 别名]
def validate_email_address(email_to, email_from, debug=False):
    # find the appropiate mail server
    domain = email_to.split('@')[1]
    remote_server = get_mx_record(domain)

    if (remote_server is None):
        print("No valid email server could be found for [%s]!" % (email_to))
        return False

    # Login into the mail exchange server
    try:
        smtp = smtplib.SMTP()
        smtp.connect(remote_server)
        if debug:
            smtp.set_debuglevel(True)
    except smtplib.SMTPConnectError as e:
        print(e)
        return False
 
    try:
        smtp.ehlo_or_helo_if_needed()
    except Exception as e:
        print(e)
        return False
 
    # First Try to verify with VRFY
    # 250 is success code. 400 or greater is error.
    v_code, v_message = smtp.verify(email_to)
    if v_code and v_code != 250:
        f_code, f_message = smtp.mail(email_from)
        # Then use RCPT to verify
        if f_code and f_code == 250:
            r_code, r_message = smtp.rcpt(email_to)
            if r_code and r_code == 250:
                return True, r_message
            if r_code and r_code == 550:
                return False, r_message
        else:
            return False
    else:
        return True, v_message

    smtp.quit()
    return False 
开发者ID:tatanus,项目名称:SPF,代码行数:46,代码来源:emails.py


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