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


Python smtplib.SMTPRecipientsRefused方法代码示例

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


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

示例1: send_rfc822

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def send_rfc822(self, rfc822_mail):
        """
        Send rfc822 mail as fetched via imap. To and from addresses are
        extracted from the rfc822 envolope.
        Returns the rfc message id of the sent message.
        """
        rewriter = MailSendRewriter(rfc822_mail)
        receivers = rewriter.get_receivers()
        rewriter.rewrite()
        if not receivers:
            raise InvalidEmail('no to address')
            # TODO: check for any rejected recepient. Fail if any fails?
        try:
            self.client.sendmail(rewriter.get_from(), receivers,
                                 rewriter.message_as_str())
        except smtplib.SMTPRecipientsRefused:
            raise InvalidEmail('server rejected recepients') 
开发者ID:Schibum,项目名称:sndlatr,代码行数:19,代码来源:gmail.py

示例2: _send_message

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [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) 
开发者ID:PacktPublishing,项目名称:Python-Programming-Blueprints,代码行数:23,代码来源:app.py

示例3: _deliver

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused as e:
            print('got SMTPRecipientsRefused', file=DEBUGSTREAM)
            refused = e.recipients
        except (OSError, smtplib.SMTPException) as e:
            print('got', e.__class__, file=DEBUGSTREAM)
            # All recipients were refused.  If the exception had an associated
            # error code, use it.  Otherwise,fake it with a non-triggering
            # exception code.
            errcode = getattr(e, 'smtp_code', -1)
            errmsg = getattr(e, 'smtp_error', 'ignore')
            for r in rcpttos:
                refused[r] = (errcode, errmsg)
        return refused 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:smtpd.py

示例4: test

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def test(self, from_addr):
        try:
            self.open()
            self.connection.ehlo_or_helo_if_needed()
            self.connection.rcpt("test@example.org")
            (code, resp) = self.connection.mail(from_addr, [])
            if code != 250:
                logger.warning(
                    "Error testing mail settings, code %d, resp: %s" % (code, resp)
                )
                raise SMTPSenderRefused(code, resp, from_addr)
            senderrs = {}
            (code, resp) = self.connection.rcpt("test@example.com")
            if (code != 250) and (code != 251):
                logger.warning(
                    "Error testing mail settings, code %d, resp: %s" % (code, resp)
                )
                raise SMTPRecipientsRefused(senderrs)
        finally:
            self.close() 
开发者ID:byro,项目名称:byro,代码行数:22,代码来源:send.py

示例5: send

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def send(self):
        s = smtplib.SMTP(self.config['server'], self.config['port'])
        s.ehlo()
        if self.config['ssl']:
            s.starttls()
            s.ehlo()
        if self.config['authenticate']:
            s.login(self.config['user'], self.config['pass'])
        msg = MIMEText(self.body)
        msg['Subject'] = self.subject
        msg['From'] = self.config['from']
        msg['To'] = ", ".join(self.recipients)
        msg['BCC'] = self.config.get('always_bcc', None)
        try:
            s.sendmail(self.config['from'], self.recipients, msg.as_string())
        except smtplib.SMTPRecipientsRefused:
            log.warn("Bad recipients for mail (not an email address?) : {recipients}".format(recipients=self.recipients))
            return False
        log.info("Sent email to {recipients}".format(recipients=self.recipients)) 
开发者ID:datastax,项目名称:cstar_perf,代码行数:21,代码来源:email_notifications.py

示例6: _send_mail_or_error_page

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def _send_mail_or_error_page(subject, content, address, request):
    try:
        send_mail(subject, content, None, [address])
    except SMTPRecipientsRefused as e:
        wrong_email, (error_code, error_msg) = e.recipients.items()[0]
        unknown = 'User unknown' in error_msg
        if not unknown:
            error_email_content = u'{0}: {1}'.format(e.__class__.__name__,
                                                     repr(e.recipients))
            send_mail(
                _('Registration: Sending mail failed: {}'.format(address)),
                error_email_content,
                None,
                [settings.TEAM_EMAIL])
        return TemplateResponse(request, 'registration/email_error.html', {
            'unknown': unknown,
            'error_code': error_code,
            'error_msg': error_msg,
            'recipient': wrong_email
        })

    return redirect('registration_request_successful', address) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:24,代码来源:views.py

示例7: send

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def send(self, request):
        if (not self.last_email) or self.last_email + timedelta(hours=12) < now():  # TODO: TIMEDELTA mit config
            old_lang = translation.get_language()
            translation.activate(self.user.language)
            link = reverse('poll_vote', args=(self.poll.url,))  # TODO: hier direkt das poll oder das Vote?
            email_content = render_to_string('invitations/mail_invite.txt', {
                'receiver': self.user.username,
                'creator': self.creator.username,
                'link': link
            })
            try:
                send_mail("Invitation to vote on {}".format(self.poll.title), email_content, None, [self.user.email])
                self.last_email = now()
                self.save()
            except SMTPRecipientsRefused:
                translation.activate(old_lang)
                messages.error(
                    request, _("The mail server had an error sending the notification to {}".format(self.user.username))
                )
            translation.activate(old_lang)
        else:
            messages.error(
                request, _("You have send an Email for {} in the last 12 Hours".format(self.user.username))
            ) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:26,代码来源:models.py

示例8: send_mail

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def send_mail(self, sender, receiver, subject="", body=""):
        """Send email from sender to receiver
        """
        mime_msg = MIMEMultipart('related')
        mime_msg['Subject'] = subject
        mime_msg['From'] = sender
        mime_msg['To'] = receiver
        msg_txt = MIMEText(body, 'plain')
        mime_msg.attach(msg_txt)
        try:
            host = getToolByName(self, 'MailHost')
            host.send(mime_msg.as_string(), immediate=True)
        except SMTPServerDisconnected as msg:
            logger.warn("SMTPServerDisconnected: %s." % msg)
        except SMTPRecipientsRefused as msg:
            raise WorkflowException(str(msg))

    # -------------------------------------------------------------------------- 
开发者ID:BaobabLims,项目名称:baobab.lims,代码行数:20,代码来源:sampleshipment.py

示例9: send_mail

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def send_mail(self, sender, receiver, subject="", body=""):
        """Send email from sender to receiver
        """
        mime_msg = MIMEMultipart('related')
        mime_msg['Subject'] = subject
        mime_msg['From'] = sender
        mime_msg['To'] = receiver
        msg_txt = MIMEText(body, 'plain')
        mime_msg.attach(msg_txt)
        try:
            host = getToolByName(self, 'MailHost')
            host.send(mime_msg.as_string(), immediate=True)
        except SMTPServerDisconnected as msg:
            logger.warn("SMTPServerDisconnected: %s." % msg)
        except SMTPRecipientsRefused as msg:
            raise WorkflowException(str(msg)) 
开发者ID:BaobabLims,项目名称:baobab.lims,代码行数:18,代码来源:shipment.py

示例10: test_fallimento_recipient

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def test_fallimento_recipient(self, mock_smtp):
        """
        In caso di fallimento del recipient  il messaggio viene rimesso in coda se entrambi
        i recipient sono stati rifiutati, altrimenti viene considerato inviato
        """
        codici = (550, 551, 552, 553, 450, 451, 452, 500, 501, 503, 521, 421)
        for codice in codici:
            msg = 'code {}'.format(codice)
            instance = mock_smtp.return_value
            for x in range(2):
                recipients = {
                    self.persone[0].persona.email: (codice, msg) if x in (1, 2) else (250, 'ok'),
                    self.persone[0].email: (codice, msg) if x in (0, 2) else (250, 'ok'),
                }
                instance.sendmail.side_effect = smtplib.SMTPRecipientsRefused(recipients=recipients)
                self._invia_msg_singolo()
                if codice == 501 or x in (0, 1):
                    self.assertEqual(Messaggio.in_coda().count(), 0)
                else:
                    self.assertEqual(Messaggio.in_coda().count(), 1)
                self._reset_coda() 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:23,代码来源:tests.py

示例11: send_email

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def send_email(destination, subject, message, reply_to_address=None):
    try:
        connection = connect()
        mmp_msg = MIMEMultipart('alternative')
        mmp_msg['Subject'] = subject
        mmp_msg['From'] = reply_to_address if reply_to_address else current_app.config['MAIL_DEFAULT_SENDER']
        mmp_msg['To'] = destination

        part1 = MIMEText(message, 'html', 'utf-8')
        mmp_msg.attach(part1)

        recipients = destination.split(',')
        recipients.append(current_app.config['ADMIN_EMAIL'])

        connection.send_message(mmp_msg, current_app.config['MAIL_DEFAULT_SENDER'], recipients)
        connection.quit()
    except SMTPRecipientsRefused as smtp_error:
        send_error_mail(smtp_error)
    except Exception as e:
        print('Exception occurred.')
        raise e 
开发者ID:HEPData,项目名称:hepdata,代码行数:23,代码来源:utils.py

示例12: internal_test

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def internal_test(smtp_targets, port, fromaddr, toaddr, data, subject, debug):
    data += "\nThis email is part of internal relay and\\or spoofing test"

    for target in smtp_targets:
        LOGGER.info("[*] Checking host %s:%s for internal spoofing", target, str(port))
        data += "\nVulnerable server is: %s" % target
        try:
            if fromaddr and toaddr:  # making sure we have both from and to addresses
                from_domain = fromaddr.split('@').pop()  # getting the domain name from the address
                to_domain = toaddr.split('@').pop()  # getting the domain name from the address
                if from_domain != to_domain:  # making sure the spoofing is for the same domain
                    # otherwise it's relay and not spoofing
                    LOGGER.error("[!] Sender and recipient domains doesn't match!")
                else:
                    with SMTP(target, port) as current_target:
                        if debug:
                            current_target.set_debuglevel(1)
                        current_target.ehlo_or_helo_if_needed()
                        msg = MIMEText(data)
                        fromaddr = fromaddr
                        toaddr = toaddr
                        msg['Subject'] = subject
                        msg['From'] = fromaddr
                        msg['To'] = toaddr

                        current_target.sendmail(fromaddr, toaddr, msg.as_string())
                        LOGGER.critical("[+] Server %s Appears to be VULNERABLE for internal "
                                        "spoofing! Used FROM: %s", target, fromaddr)
            else:
                LOGGER.critical("[!] Problem with FROM and/or TO address!")
                exit(1)
        except (SMTPRecipientsRefused, SMTPSenderRefused) as e:
            LOGGER.critical("[!] SMTP Error: %s\n[-] Server: %s NOT vulnerable or TO address "
                            "doesn't exist!", str(e), target)
        except ConnectionRefusedError:
            LOGGER.critical("[!] Connection refused by host %s", target)
        except KeyboardInterrupt:
            LOGGER.critical("[CTRL+C] Stopping...")
            exit(1)
        except Exception as e:
            excptn(e) 
开发者ID:xFreed0m,项目名称:SMTPTester,代码行数:43,代码来源:SMTPTester.py

示例13: _deliver

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused, e:
            print >> DEBUGSTREAM, 'got SMTPRecipientsRefused'
            refused = e.recipients 
开发者ID:glmcdona,项目名称:meddle,代码行数:15,代码来源:smtpd.py

示例14: _deliver

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused, e:
            logger.debug('got SMTPRecipientsRefused')
            refused = e.recipients 
开发者ID:34nm,项目名称:gsmtpd,代码行数:15,代码来源:server.py

示例15: __send_mail

# 需要导入模块: import smtplib [as 别名]
# 或者: from smtplib import SMTPRecipientsRefused [as 别名]
def __send_mail(self, nameSite, link):
        server = smtplib.SMTP("smtp.gmail.com:587")
        server.starttls()
        try:
            server.login(self.__MAIL, self.__PSW)
            subj = "The site \"" + nameSite + "\" has been changed!"
            msg = "Subject: " + subj + "\n" + subj + "\nLink: " + link
            mail = self.execute_fetch_all(
                "SELECT Registered.mail FROM Users, Registered WHERE Registered.mail = Users.mail AND mailnotification = 'True' AND name=?",
                (nameSite,))
            for address in mail:
                try:
                    server.sendmail(self.__MAIL, address, msg)
                except smtplib.SMTPRecipientsRefused:
                    print("Error with this e-mail destination address: " + address)
            server.close()
            telegram = self.execute_fetch_all(
                "SELECT telegram FROM Users, Registered WHERE telegramnotification = 'True' AND name=? AND Users.mail = Registered.mail",
                (nameSite,))
            for t in telegram:
                try:
                    self.__tb.send_message(t[0], subj + "\nLink: " + link)
                except telebot.apihelper.ApiException:
                    print("Bot kicked from " + t[0], ", removing from DB...")
                    self.execute_query(
                        "DELETE FROM Registered WHERE mail = (SELECT mail FROM Users WHERE telegram = ?)",
                        (t[0],))
                    self.execute_query("DELETE FROM Users WHERE telegram = ?", (t[0],))
        except smtplib.SMTPAuthenticationError:
            print("Error in the login process") 
开发者ID:ilteoood,项目名称:SiteAlert-Python,代码行数:32,代码来源:SiteAlert.py


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