Python smtplib.SMTPNotSupportedError() Examples

The following are 11 code examples of smtplib.SMTPNotSupportedError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module smtplib , or try the search function .
Example #1
Source File: smtpconnection.py    From smtp-email-spoofer-py with GNU General Public License v3.0 6 votes vote down vote up
def login(self, username, password):
        try:
            return self.server.login(username, password)
        except smtplib.SMTPAuthenticationError:
            logger.error('The server did not accept the username/password combination.')
            return False
        except smtplib.SMTPNotSupportedError:
            logger.error('The AUTH command is not supported by the server.')
            exit(1)
        except smtplib.SMTPException:
            logger.error('Encountered an error during authentication.')
            exit(1) 
Example #2
Source File: test_smtplib.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_smtputf8_NotSupportedError_if_no_server_support(self):
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        smtp.ehlo()
        self.assertTrue(smtp.does_esmtp)
        self.assertFalse(smtp.has_extn('smtputf8'))
        self.assertRaises(
            smtplib.SMTPNotSupportedError,
            smtp.sendmail,
            'John', 'Sally', '', mail_options=['BODY=8BITMIME', 'SMTPUTF8'])
        self.assertRaises(
            smtplib.SMTPNotSupportedError,
            smtp.mail, 'John', options=['BODY=8BITMIME', 'SMTPUTF8']) 
Example #3
Source File: test_smtplib.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self):
        msg = EmailMessage()
        msg['From'] = "Páolo <főo@bar.com>"
        msg['To'] = 'Dinsdale'
        msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        self.assertRaises(smtplib.SMTPNotSupportedError,
                          smtp.send_message(msg)) 
Example #4
Source File: test_smtplib.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_smtputf8_NotSupportedError_if_no_server_support(self):
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        smtp.ehlo()
        self.assertTrue(smtp.does_esmtp)
        self.assertFalse(smtp.has_extn('smtputf8'))
        self.assertRaises(
            smtplib.SMTPNotSupportedError,
            smtp.sendmail,
            'John', 'Sally', '', mail_options=['BODY=8BITMIME', 'SMTPUTF8'])
        self.assertRaises(
            smtplib.SMTPNotSupportedError,
            smtp.mail, 'John', options=['BODY=8BITMIME', 'SMTPUTF8']) 
Example #5
Source File: test_smtplib.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self):
        msg = EmailMessage()
        msg['From'] = "Páolo <főo@bar.com>"
        msg['To'] = 'Dinsdale'
        msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        self.assertRaises(smtplib.SMTPNotSupportedError,
                          smtp.send_message(msg)) 
Example #6
Source File: test_smtplib.py    From android_universal with MIT License 5 votes vote down vote up
def test_smtputf8_NotSupportedError_if_no_server_support(self):
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        smtp.ehlo()
        self.assertTrue(smtp.does_esmtp)
        self.assertFalse(smtp.has_extn('smtputf8'))
        self.assertRaises(
            smtplib.SMTPNotSupportedError,
            smtp.sendmail,
            'John', 'Sally', '', mail_options=['BODY=8BITMIME', 'SMTPUTF8'])
        self.assertRaises(
            smtplib.SMTPNotSupportedError,
            smtp.mail, 'John', options=['BODY=8BITMIME', 'SMTPUTF8']) 
Example #7
Source File: test_smtplib.py    From android_universal with MIT License 5 votes vote down vote up
def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self):
        # This test is located here and not in the SMTPUTF8SimTests
        # class because it needs a "regular" SMTP server to work
        msg = EmailMessage()
        msg['From'] = "Páolo <főo@bar.com>"
        msg['To'] = 'Dinsdale'
        msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        with self.assertRaises(smtplib.SMTPNotSupportedError):
            smtp.send_message(msg) 
Example #8
Source File: delivery.py    From mail-security-tester with GNU General Public License v3.0 4 votes vote down vote up
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) 
Example #9
Source File: smtp.py    From Camelishing with MIT License 4 votes vote down vote up
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) 
Example #10
Source File: __init__.py    From king-phisher-plugins with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def send_alert(self, alert_subscription):
		user = alert_subscription.user
		if not user.email_address:
			self.logger.debug("user {0} has no email address specified, skipping SMTP alert".format(user.name))
			return False

		msg = self.create_message(alert_subscription)
		if not msg:
			return False

		if self.config['smtp_ssl']:
			SmtpClass = smtplib.SMTP_SSL
		else:
			SmtpClass = smtplib.SMTP
		try:
			server = SmtpClass(self.config['smtp_server'], self.config['smtp_port'], timeout=15)
			server.ehlo()
		except smtplib.SMTPException:
			self.logger.warning('received an SMTPException while connecting to the SMTP server', exc_info=True)
			return False
		except socket.error:
			self.logger.warning('received a socket.error while connecting to the SMTP server')
			return False

		if not self.config['smtp_ssl'] and 'starttls' in server.esmtp_features:
			self.logger.debug('target SMTP server supports the STARTTLS extension')
			try:
				server.starttls()
				server.ehlo()
			except smtplib.SMTPException:
				self.logger.warning('received an SMTPException wile negotiating STARTTLS with SMTP server', exc_info=True)
				return False

		if self.config['smtp_username']:
			try:
				server.login(self.config['smtp_username'], self.config['smtp_password'])
			except smtplib.SMTPNotSupportedError:
				self.logger.debug('SMTP server does not support authentication')
			except smtplib.SMTPException as error:
				self.logger.warning("received an {0} while authenticating to the SMTP server".format(error.__class__.__name__))
				server.quit()
				return False

		mail_options = ['SMTPUTF8'] if server.has_extn('SMTPUTF8') else []
		try:
			server.sendmail(self.config['smtp_email'], alert_subscription.user.email_address, msg, mail_options)
		except smtplib.SMTPException as error:
			self.logger.warning("received error {0} while sending mail".format(error.__class__.__name__))
			return False
		finally:
			server.quit()
		self.logger.debug("successfully sent an email campaign alert to user: {0}".format(user.name))
		return True 
Example #11
Source File: NotificationHelper.py    From AIL-framework with GNU Affero General Public License v3.0 4 votes vote down vote up
def sendEmailNotification(recipient, alert_name, content):

    sender = config_loader.get_config_str("Notifications", "sender")
    sender_user = config_loader.get_config_str("Notifications", "sender_user")
    sender_host = config_loader.get_config_str("Notifications", "sender_host")
    sender_port = config_loader.get_config_int("Notifications", "sender_port")
    sender_pw = config_loader.get_config_str("Notifications", "sender_pw")
    if sender_pw == 'None':
        sender_pw = None

    # raise an exception if any of these is None
    if (sender is None or
        sender_host is None or
        sender_port is None
        ):
        raise Exception('SMTP configuration (host, port, sender) is missing or incomplete!')

    try:
        if sender_pw is not None:
            try:
                smtp_server = smtplib.SMTP(sender_host, sender_port)
                smtp_server.starttls()
            except smtplib.SMTPNotSupportedError:
                print("The server does not support the STARTTLS extension.")
                smtp_server = smtplib.SMTP_SSL(sender_host, sender_port)

            smtp_server.ehlo()
            if sender_user is not None:
                smtp_server.login(sender_user, sender_pw)
            else:
                smtp_server.login(sender, sender_pw)
        else:
            smtp_server = smtplib.SMTP(sender_host, sender_port)

        mime_msg = MIMEMultipart()
        mime_msg['From'] = sender
        mime_msg['To'] = recipient
        mime_msg['Subject'] = "AIL Framework " + alert_name + " Alert"

        body = content
        mime_msg.attach(MIMEText(body, 'plain'))

        smtp_server.sendmail(sender, recipient, mime_msg.as_string())
        smtp_server.quit()
        print('Send notification ' + alert_name + ' to '+recipient)

    except Exception as err:
        traceback.print_tb(err.__traceback__)
        publisher.warning(err)