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


Python mail.MailSender类代码示例

本文整理汇总了Python中scrapy.mail.MailSender的典型用法代码示例。如果您正苦于以下问题:Python MailSender类的具体用法?Python MailSender怎么用?Python MailSender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GuguPipeline

class GuguPipeline(object):

  def __init__(self, mail_to):
    self.mailer = MailSender()
    self.mail_to = mail_to
    if mail_to:
      log.msg('Emails will be sent to %s' % mail_to, level=logging.INFO)

  @classmethod
  def from_settings(cls, settings):
    mail_to = settings['GUGU_PIPELINE_MAIL_TO']
    return cls(mail_to)

  def process_item(self, item, spider):
    if re.search(GUGU_PATTERN, item['lyrics']):
      item['match'] = 'true'
      self.send_email(item)
    else:
      item['match'] = 'false'
    return item

  def send_email(self, item):
    if not self.mail_to:
      return
    subject = "Found a match: {artist} - {title}".format(**item)
    body = """URL: {url}

{lyrics}
""".format(**item)
    self.mailer.send(to=[self.mail_to], subject=subject, body=body)
开发者ID:clee704,项目名称:gugu,代码行数:30,代码来源:pipelines.py

示例2: SpiderOpenCloseLogging

class SpiderOpenCloseLogging(object):

    def __init__(self):
        dispatcher.connect(self.spider_opened, signal=signals.spider_opened)
        dispatcher.connect(self.spider_closed, signal=signals.spider_closed)
        self.mailer = MailSender()
        self.mailer.smtphost = "smtp.sina.cn"
        self.mailer.smtpuser = "[email protected]"
        self.mailer.smtppass = "liuqingfei001"
        self.mailer.mailfrom = "[email protected]"

    def spider_opened(self, spider):
        log.msg("opened spider %s" % spider.name)
        self.mailer.send(to=["[email protected]"], subject="scrapy running", body="scrapy is start")

    def spider_closed(self, spider):
        if spider.domain:
            param =(spider.sales_num,spider.money,spider.queue_id)
            spider.cur.execute("update admin_queue set sales=%s , money=%s where id=%s",param)
            spider.conn.commit()
            spider.cur.close()
            spider.conn.close()
            mail_content = str(spider.shop_name)+"\n"
            mail_content += "30天销量:"+str(spider.sales_num)+" \n30天成交额:"+str(spider.money)+"\n店铺地址:"+str(spider.domain)+"\n"
            mail_content+="---------------------------------------\n"
            mail_content+=spider.shopinfo_str
            mail_title = str(spider.shop_name) +' 数据报告'
            self.mailer.send(to=[str(spider.mailto)], subject=mail_title, body=mail_content)
        log.msg("closed spider %s" % spider.name)
开发者ID:liuwei000000,项目名称:dirbot-master,代码行数:29,代码来源:signals.py

示例3: test_send_html

    def test_send_html(self):
        mailsender = MailSender(debug=True)
        mailsender.send(to=['[email protected]'], subject='subject', body='<p>body</p>', mimetype='text/html', _callback=self._catch_mail_sent)

        msg = self.catched_msg['msg']
        self.assertEqual(msg.get_payload(), '<p>body</p>')
        self.assertEqual(msg.get('Content-Type'), 'text/html')
开发者ID:01-,项目名称:scrapy,代码行数:7,代码来源:test_mail.py

示例4: test_send_attach_utf8

    def test_send_attach_utf8(self):
        subject = u'sübjèçt'
        body = u'bödÿ-àéïöñß'
        attach = BytesIO()
        attach.write(body.encode('utf-8'))
        attach.seek(0)
        attachs = [('attachment', 'text/plain', attach)]

        mailsender = MailSender(debug=True)
        mailsender.send(to=['[email protected]'], subject=subject, body=body,
                        attachs=attachs, charset='utf-8', _callback=self._catch_mail_sent)

        assert self.catched_msg
        self.assertEqual(self.catched_msg['subject'], subject)
        self.assertEqual(self.catched_msg['body'], body)

        msg = self.catched_msg['msg']
        self.assertEqual(msg['subject'], subject)
        self.assertEqual(msg.get_charset(), Charset('utf-8'))
        self.assertEqual(msg.get('Content-Type'), 'multipart/mixed; charset="utf-8"')

        payload = msg.get_payload()
        assert isinstance(payload, list)
        self.assertEqual(len(payload), 2)

        text, attach = payload
        self.assertEqual(text.get_payload(decode=True).decode('utf-8'), body)
        self.assertEqual(text.get_charset(), Charset('utf-8'))
        self.assertEqual(attach.get_payload(decode=True).decode('utf-8'), body)
开发者ID:01-,项目名称:scrapy,代码行数:29,代码来源:test_mail.py

示例5: test_send_attach

    def test_send_attach(self):
        attach = BytesIO()
        attach.write(b'content')
        attach.seek(0)
        attachs = [('attachment', 'text/plain', attach)]

        mailsender = MailSender(debug=True)
        mailsender.send(to=['[email protected]'], subject='subject', body='body',
                       attachs=attachs, _callback=self._catch_mail_sent)

        assert self.catched_msg
        self.assertEqual(self.catched_msg['to'], ['[email protected]'])
        self.assertEqual(self.catched_msg['subject'], 'subject')
        self.assertEqual(self.catched_msg['body'], 'body')

        msg = self.catched_msg['msg']
        self.assertEqual(msg['to'], '[email protected]')
        self.assertEqual(msg['subject'], 'subject')

        payload = msg.get_payload()
        assert isinstance(payload, list)
        self.assertEqual(len(payload), 2)

        text, attach = payload
        self.assertEqual(text.get_payload(decode=True), b'body')
        self.assertEqual(text.get_charset(), Charset('us-ascii'))
        self.assertEqual(attach.get_payload(decode=True), b'content')
开发者ID:01-,项目名称:scrapy,代码行数:27,代码来源:test_mail.py

示例6: stats_spider_closed

 def stats_spider_closed(self, spider, spider_stats):
     mail = MailSender()
     body = "Global stats\n\n"
     body += "\n".join("%-50s : %s" % i for i in stats.get_stats().items())
     body += "\n\n%s stats\n\n" % spider.name
     body += "\n".join("%-50s : %s" % i for i in spider_stats.items())
     mail.send(self.recipients, "Scrapy stats for: %s" % spider.name, body)
开发者ID:rishipatel,项目名称:scrapy,代码行数:7,代码来源:statsmailer.py

示例7: test_send_attach

    def test_send_attach(self):
        attach = StringIO()
        attach.write('content')
        attach.seek(0)
        attachs = [('attachment', 'text/plain', attach)]

        mailsender = MailSender(debug=True, crawler=self.crawler)
        mailsender.send(to=['[email protected]'], subject='subject', body='body',
                       attachs=attachs)

        assert self.catched_msg
        self.assertEqual(self.catched_msg['to'], ['[email protected]'])
        self.assertEqual(self.catched_msg['subject'], 'subject')
        self.assertEqual(self.catched_msg['body'], 'body')

        msg = self.catched_msg['msg']
        self.assertEqual(msg['to'], '[email protected]')
        self.assertEqual(msg['subject'], 'subject')

        payload = msg.get_payload()
        assert isinstance(payload, list)
        self.assertEqual(len(payload), 2)

        text, attach = payload
        self.assertEqual(text.get_payload(decode=True), 'body')
        self.assertEqual(attach.get_payload(decode=True), 'content')
开发者ID:frrp,项目名称:scrapy,代码行数:26,代码来源:test_mail.py

示例8: close

    def close(spider, reason):
        # send email when spider closed
        if spider.email_content.strip():
            mailer = MailSender(mailfrom="[email protected]", smtphost="smtp.gmail.com", smtpport=587, smtpuser="[email protected]",smtppass="6380sivan6756")
            mailer.send(to=["[email protected]", "[email protected]"], cc=["[email protected]"], subject= "[Movies Here] " + spider.keyword + " is coming!!!", body=spider.email_content)

        closed = getattr(spider, 'closed', None)
        if callable(closed):
            return closed(reason)
开发者ID:joissivan,项目名称:PersonalScanner,代码行数:9,代码来源:torrent.py

示例9: spider_error

 def spider_error(failure):
     """Send errors email."""
     from_email = RYANAIR_SETTINGS['FROM_EMAIL']
     to_email = RYANAIR_SETTINGS['FAILURE_EMAIL']
     mailer = MailSender(mailfrom=from_email)
     mailer.send(
         to=[to_email],
         subject="Ryanair flights error",
         body=failure.getErrorMessage(),
     )
开发者ID:MaximeDevalland,项目名称:ryanair,代码行数:10,代码来源:ryanair.py

示例10: close_spider

    def close_spider(self, spider):
        info = self.info.pop(spider.name)
        if info is not None:
            outdir = spider.outdir
            outpath = os.path.join(outdir, "links.json")
            items = info['items']
            with open(outpath, 'w') as f:
                f.write(json.dumps([dict(i) for i in items]))

            errors = [
                i for i in items if i['status'] != 200 or
                i['validation_error'] or i['header_errors']]
            if errors:
                with open(os.path.join(outdir, 'ERRORS'), 'w') as f:
                    f.write(json.dumps([dict(i) for i in errors]))

                message = []
                for i in errors:
                    item_message = ["===\nURL: {0}\n\n".format(i['url'])]

                    status = i['status']
                    if status != 200:
                        item_message.append(
                            "Failed retrieval with status: {0}\n".format(
                                status))

                    if i['validation_error']:
                        item_message.append("Failed validation.\n\n")


                    header_errors = i['header_errors']
                    if header_errors:
                        item_message.append(
                            ("Failed header checks with the following "
                             "errors:\n{0}\n").format(
                                 "\n".join(header_errors)))

                    if len(item_message) > 1:
                        message += item_message

                message.append("\nSee %s for details of validation errors." %
                               outdir)

                email_body = "".join(message)
                with open(os.path.join(outdir, 'REPORT'), 'w') as f:
                    f.write(email_body)

                send_to = spider.send_to
                if send_to is not None:
                    sender = MailSender(mailfrom="[email protected]")
                    sender.send([send_to], "Smoketest failure", email_body)
            else:
                with open(os.path.join(outdir, 'CLEAN'), 'w') as f:
                    f.write("yes\n")
开发者ID:mangalam-research,项目名称:btw_smoketest,代码行数:54,代码来源:pipelines.py

示例11: wrapper

 def wrapper(*args, **kwargs):
     max_attempts = settings.getint("MAX_MONGO_RECONNECT_ATTEMPTS", MAX_AUTO_RECONNECT_ATTEMPTS)
     mail = MailSender()
     for attempt in xrange(max_attempts):
         try:
             return mongo_op_func(*args, **kwargs)
         except AutoReconnect as e:
             wait_t = 1 + attempt # exponential back off
             log.msg("PyMongo auto-reconnecting... %s. Waiting %.1f seconds."%(str(e), wait_t), log.INFO)
             mail.send(to=[settings.get('MAIL_TO')], subject='PyMongo auto-reconnecting....', \
                   body="%s\n%s"%(e, traceback.format_exc()))
             time.sleep(wait_t)
开发者ID:magicdog,项目名称:scrapyextract,代码行数:12,代码来源:mongoconnection.py

示例12: close

 def close(self, reason):
     self.logger.info(reason)
     mailfrom = '[email protected]'
     smtphost = 'smtp.163.com'
     smtpport = 25,
     smtpuser = 'west_blo[email protected]'
     smtppass = '1451518065ll'
     smtpssl = True
     mailer = MailSender(mailfrom=mailfrom, smtphost=smtphost, smtpuser=smtpuser, smtppass=smtppass)
     # mailer = MailSender.from_settings(settings.MAIL)
     mailer.send(to=['[email protected]'], subject='Send Email Test by Scrapy MailSender!', body='Holle world!')
     print settings.MAIL['MAIL_USER']
开发者ID:5uw1st,项目名称:Spiders,代码行数:12,代码来源:cfdaspider.py

示例13: send_email

    def send_email(self, to=[], cc=[], subject="爬虫运行异常", body="", attachs=[]):
	# 如果收件人邮箱为空, 则发送到root账户的邮箱
        if len(to) == 0:
	    root_user = User.objects.filter(is_superuser=1)
	    if len(root_user) == 0:
	        raise Exception("root账户不存在, 请添加root账户和root账户的邮箱")
	    root_user_email = root_user[0].email
	    if root_user_email == None or root_user_email == "":
	        raise Exception("root账户没有配置邮箱, 请添加root账户的邮箱")
	    self.email_receiver.append(root_user_email)

	mailer = MailSender()
	mailer.send(to=to, cc=cc, subject=subject.encode("utf-8"), body=body.encode("utf-8"), attachs=attachs)
开发者ID:dingwf,项目名称:hotel-scrapy,代码行数:13,代码来源:email.py

示例14: MemoryDebugger

class MemoryDebugger(object):

    def __init__(self):
        try:
            import libxml2
            self.libxml2 = libxml2
        except ImportError:
            self.libxml2 = None
        if not settings.getbool('MEMDEBUG_ENABLED'):
            raise NotConfigured

        self.mail = MailSender()
        self.rcpts = settings.getlist('MEMDEBUG_NOTIFY')

        dispatcher.connect(self.engine_started, signals.engine_started)
        dispatcher.connect(self.engine_stopped, signals.engine_stopped)

    def engine_started(self):
        if self.libxml2:
            self.libxml2.debugMemory(1)

    def engine_stopped(self):
        figures = self.collect_figures()
        report = self.create_report(figures)
        self.log_or_send_report(report)

    def collect_figures(self):
        gc.collect()

        figures = []
        figures.append(("Objects in gc.garbage", len(gc.garbage), ""))
        if self.libxml2:
            self.libxml2.cleanupParser()
            figures.append(("libxml2 memory leak", self.libxml2.debugMemory(1), "bytes"))
        return figures

    def create_report(self, figures):
        s = ""
        s += "SCRAPY MEMORY DEBUGGER RESULTS\n\n"
        for f in figures:
            s += "%-30s : %d %s\n" % f
        if settings.getbool('TRACK_REFS'):
            s += os.linesep
            s += format_live_refs()
        return s

    def log_or_send_report(self, report):
        if self.rcpts:
            self.mail.send(self.rcpts, "Scrapy Memory Debugger results at %s" % \
                socket.gethostname(), report)
        log.msg(report)
开发者ID:bihicheng,项目名称:scrapy,代码行数:51,代码来源:memdebug.py

示例15: test_send

    def test_send(self):
        mailsender = MailSender(debug=True)
        mailsender.send(to=['[email protected]'], subject='subject', body='body', _callback=self._catch_mail_sent)

        assert self.catched_msg

        self.assertEqual(self.catched_msg['to'], ['[email protected]'])
        self.assertEqual(self.catched_msg['subject'], 'subject')
        self.assertEqual(self.catched_msg['body'], 'body')

        msg = self.catched_msg['msg']
        self.assertEqual(msg['to'], '[email protected]')
        self.assertEqual(msg['subject'], 'subject')
        self.assertEqual(msg.get_payload(), 'body')
开发者ID:00gpowe,项目名称:scrapy,代码行数:14,代码来源:test_mail.py


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