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


Python mailer.Mailer类代码示例

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


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

示例1: test_create_mail__attach_text_and_zip

    def test_create_mail__attach_text_and_zip(self):
        mail = MailData()
        mail.recipients = ["[email protected]"]
        mail.subject = "Test mail"
        mail.body = "Test body"
        mail.file_attachments = ["test.txt", "test.zip"]
        text_file = FileStub("TEXT")
        zip_file = FileStub("BINARY")
        Mailer.open_file = MagicMock(side_effect = [text_file, zip_file])
        mimetypes.guess_type = MagicMock(side_effect = [("text/plain", None), ("application/zip", None)])

        mailer = Mailer()
        result = mailer.create_mail(mail)

        self.assertEqual("[email protected]", result["To"])
        self.assertEqual(mail.subject, result["Subject"])
        self.assertTrue(result.is_multipart())
        messages = result.get_payload()
        self.assertEqual(3, len(messages))
        text_message = messages[0]
        self.assertEqual("text/plain", text_message.get_content_type())
        self.assertEqual(mail.body, text_message.get_payload())
        attachment1_message = messages[1]
        self.assertEqual("text/plain", attachment1_message.get_content_type())
        self.assertEqual("TEXT", attachment1_message.get_payload())
        attachment2_message = messages[2]
        self.assertEqual("application/zip", attachment2_message.get_content_type())
        self.assertEqual(base64.b64encode("BINARY"), attachment2_message.get_payload())
开发者ID:efalive,项目名称:efalive,代码行数:28,代码来源:test_mailer.py

示例2: notify

def notify(args):
    config = parse_config(args.config)  
    db = database.WatchDb(db_path=DB_PATH)
    LOGGER.info("Notify if something is not working...")
    if db.get_status(config['notify']['track_last']):
        LOGGER.info("Everything seems to be ok.")
    else:
        LOGGER.warning("One of tests failed, generate report.")
        env = Environment(loader=FileSystemLoader(DIRECTORY))
        template = env.get_template('template.html')
        body = template.render(table=db.get_latest(config['notify']['track_last']))
        LOGGER.info("Sending email...")
        sender = Mailer(
            config['smtp']['host'],
            port=config['smtp']['port'],
            usr=config['smtp']['user'],
            pwd=config['smtp']['password'],
        )
        message = Message(
            From=config['smtp']['user'],
            To=config['notify']['email'],
        )
        message.Subject = config['notify']['subject']
        message.Html = body
        sender.send(message)
开发者ID:dawid1stanek,项目名称:guardian,代码行数:25,代码来源:__main__.py

示例3: report_html

 def report_html(self, target):
     if not target:
         return
     view = report.HtmlView(self._table_list, self._title)
     view.set_encoding(self._options.encoding)
     if '@' in target:
         recp = []
         for mail_to in target.split(';'):
             mail_to = mail_to.strip()
             if not mail_to:
                 continue
             logger.info('send mail to %s', mail_to)
             recp.append(mail_to)
         msg = Message(
                 recp = recp,
                 subject = self._title,
                 html = view.show())
         mailer = Mailer()
         mailer.send(msg)
     else:
         path = os.path.abspath(target)
         logger.info('save html report in: %s', path)
         fp = open(path, 'wb')
         fp.write(view.show())
         fp.close()
     return
开发者ID:zhengxle,项目名称:python,代码行数:26,代码来源:sendreport.py

示例4: test_send_mail__unencrypted_authorized

    def test_send_mail__unencrypted_authorized(self, smtp_mock):
        mail_data = MailData()
        mail_data.recipients = ["[email protected]"]
        mail_data.subject = "Test mail"
        mail_data.body = "Test body"
        mailer_config = MailerConfig()
        mailer_config.smtp_host = "localhost"
        mailer_config.smtp_port = 25
        mailer_config.use_starttls = False
        mailer_config.use_ssl = False
        mailer_config.user = "Tester"
        mailer_config.password = "Secret"
        mailer_config.sender = "[email protected]"

        mailer = Mailer()
        mail = mailer.create_mail(mail_data)
        mailer.send_mail(mailer_config, mail)

        assert smtp_mock.call_count == 1
        assert smtp_mock.call_args == ((mailer_config.smtp_host, mailer_config.smtp_port),)
        assert smtp_mock.return_value.starttls.call_count == 0
        assert smtp_mock.return_value.login.call_count == 1
        assert smtp_mock.return_value.login.call_args == ((mailer_config.user, mailer_config.password),)
        assert smtp_mock.return_value.sendmail.call_count == 1
        assert smtp_mock.return_value.sendmail.call_args == ((mail["From"], mail["To"], mail.as_string()),)
        assert smtp_mock.return_value.quit.call_count == 1
开发者ID:efalive,项目名称:efalive,代码行数:26,代码来源:test_mailer.py

示例5: send

    def send(self, from_address, to_address, subject, body=None, html=True):
        try:
            message = Message(
                From=from_address,
                To=to_address,
                charset=self.charset
            )

            if body is None:
                body = ''
            self.body = body

            message.Subject = "%s - %s" % (self.subject_prefix, subject)
            message.Html = self.body
            message.Body = self.body
        except Exception as e:
            log.exception('[scaffold_mailer] - Failed to create message object for mailer')
            return False

        try:
            sender = Mailer(
                host=self.config.get('host'),
                port=self.config.get('port'),
                use_tls=self.config.get('use_tls', False),
                use_ssl=True,
                usr=self.config.get('username'),
                pwd=self.config.get('password'))
            sender.send(message)
        except Exception as e:
            log.exception('[scaffold_mailer] - Failed to connect to smtp sever and send message with subject: %s' % message.Subject)
            return False
        return True
开发者ID:maidstone-hackspace,项目名称:maidstone-hackspace,代码行数:32,代码来源:mail.py

示例6: sendmail

def sendmail(mailto, subject, html='', text='', textfile='', htmlfile='', attachments=''):
    '''send mail'''
    if not mailto:
        print 'Error: Empty mailto address.\n'
        return

    mailto = [sb.strip() for sb in mailto.split(',')]
    if attachments:
        attachments = [att.strip() for att in attachments.split(',')] 
    else:
        attachments = []
    
    #USERNAME = hostname()
    subject = "%s-[%s]" % ( subject, hostname())

    message = Message(From=USERNAME, To=mailto, Subject=subject, attachments=attachments)
    message.Body = text
    message.Html = html
    message.charset = 'utf8'
    try:
        if htmlfile:
            message.Html += open(htmlfile, 'r').read()
        if textfile:
            message.Body += open(textfile, 'r').read()
    except IOError:
        pass

    for att in attachments:
        message.attach(att)

    sender = Mailer(SERVER,port=465, use_tls=True, usr=USERNAME, pwd=PASSWD)
    #sender = Mailer(SERVER)
    #sender.login(USERNAME, PASSWD)
    sender.send(message)
开发者ID:cychenyin,项目名称:windmill,代码行数:34,代码来源:mailman.py

示例7: send_email

def send_email(user, pwd, recipient, subject, body):

    gmail_user = user
    gmail_pwd = pwd
    FROM = user
    TO = recipient if type(recipient) is list else [recipient]
    SUBJECT = subject
    TEXT = body

    message = Message(From=FROM,
                      To=TO)

    message.Subject = SUBJECT
    message.Html = """
                        <html>
                          <head></head>
                          <body>
                            <p>Hi! You've requested the UTNC practice schedule<br>
                               How are you?<br>
                               Here is the <a href="http://www.python.org">link</a> you wanted.
                            </p>
                          </body>
                        </html>
                        """

    sender = Mailer('smtp.gmail.com',port=587, use_tls=True, usr=gmail_user, pwd=gmail_pwd)
    sender.send(message)
开发者ID:Syanna,项目名称:UTNC_email,代码行数:27,代码来源:Email.py

示例8: turnOnLight

def turnOnLight(date, value):
  light(True)
  message = "lights is on at {}".format(datetime.datetime.now())
  user = credentials["email"]["username"]
  password = credentials["email"]["password"]
  mailer = Mailer(user, password)
  mailer.send("[email protected]", "Light is on", message)
开发者ID:yulrizka,项目名称:homeward-indicator,代码行数:7,代码来源:main.py

示例9: alert_email

def alert_email(feed, cfg, entry):
    """Sends alert via email.

    Args:
        feed (:py:class:`Feed`): the feed
        cfg (dict):              output config
        entry (dict):            the feed entry
    """
    logger = logging.LoggerAdapter(log, extra = {
        'feed':  feed.name,
        'group': feed.group['name'],
    })

    logger.debug(f"[{feed.name}] Alerting email: {entry.title}")

    description = strip_html(entry.description)

    try:
        smtp = Mailer(host=cfg['server'])
        message = Message(charset="utf-8", From=cfg['from'], To=cfg['to'],
                          Subject = f"{feed.group['name']} Alert: ({feed.name}) {entry.title}")
        message.Body = f"Feed: {feed.name}\nDate: {entry.datestring}\n\n{description}"
        message.header('X-Mailer', 'rssalertbot')
        smtp.send(message)

    except Exception:
        logger.exception(f"[{feed.name}] Error sending mail")
开发者ID:jwplayer,项目名称:rssalertbot,代码行数:27,代码来源:alerts.py

示例10: mail_manifest

 def mail_manifest(self, emailfrom, emailto):
     message = Message(From=emailfrom, To=emailto)
     message.Subject = "Manifest"
     message.Html = self.fetch_manifest()
     
     sender = Mailer('localhost')
     sender.send(message)
开发者ID:OdinsHat,项目名称:citylink-utils,代码行数:7,代码来源:citylink.py

示例11: send_reset_email

 def send_reset_email(self):
     self.token = os.urandom(32).encode('hex')
     sender = Mailer('localhost', port=25)
     msg = Message(From="[email protected]", To=[self.email],
                   charset="utf-8")
     msg.Subject = u'Accès trombinoscope ACR'
     msg.Body = _BODY % (unicode(self.token), unicode(self.login))
     sender.send([msg])
开发者ID:AcrDijon,项目名称:trombi,代码行数:8,代码来源:mappings.py

示例12: _send

 def _send(self, subject, htmlbody, textbody):
     for to in config().backupmailrecipients:
         logger().info("Sent backup report to [%s] via SMTP:%s" % (to, config().smtphost))
         message = Message(From=config().backupmailfrom, To=to, charset="utf-8")
         message.Subject = subject
         message.Html = htmlbody
         message.Body = textbody
         sender = Mailer(config().smtphost)
         sender.send(message)
开发者ID:Nextpertise,项目名称:autorsyncbackup,代码行数:9,代码来源:statusemail.py

示例13: send_email

def send_email(msg):
    from mailer import Mailer, Message
    mail_msg = Message(From="监听者<%s>"%(os.environ["MAIL_ADDR"]),
                    To=["[email protected]"],
                    charset="utf-8")
    mail_msg.Subject = "Watchpmc Report"
    mail_msg.Html = msg
    sender = Mailer(host="smtp.yeah.net", usr=os.environ["MAIL_ADDR"], pwd=os.environ["MAIL_PASS"])
    sender.send(mail_msg)
开发者ID:kuanghy,项目名称:pps,代码行数:9,代码来源:watchpmc.py

示例14: _send

 def _send(self, subject, htmlbody):
     for to in config().backupmailrecipients:
         logger().info("INFO: Sent backup report to [%s] via SMTP:%s" % (to, config().smtphost))
         message = Message(From=config().backupmailfrom, To=to, charset="utf-8")
         message.Subject = subject
         message.Html = htmlbody
         message.Body = """This is an HTML e-mail with the backup overview, please use a HTML enabled e-mail client."""
         sender = Mailer(config().smtphost)
         sender.send(message)
开发者ID:WeszNL,项目名称:autorsyncbackup,代码行数:9,代码来源:statusemail.py

示例15: send

 def send(self):
     """Send the email described by this object."""
     message = Message(From=self.sender,
                       To=self.to,
                       charset="utf-8")
     message.Subject = self.subject
     message.Body = self.body
     mailer = Mailer(self.smtp_server)
     mailer.send(message)
开发者ID:JoseEspinosa,项目名称:bbcflib,代码行数:9,代码来源:email.py


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