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


Python encoders.encode_base64方法代码示例

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


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

示例1: __init__

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def __init__(self, _data, _subtype='octet-stream',
                 _encoder=encoders.encode_base64, **_params):
        """Create an application/* type MIME document.

        _data is a string containing the raw application data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')
        MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
        self.set_payload(_data)
        _encoder(self) 
开发者ID:glmcdona,项目名称:meddle,代码行数:23,代码来源:application.py

示例2: attach

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def attach(self, filename, content, content_type=None):
        if not self.multipart:
            msg = self.new_message()
            msg.add_header("Content-Type", "multipart/mixed")
            msg.attach(self.message)
            self.message = msg
            self.multipart = True
                        
        import mimetypes
        try:
            from email import encoders
        except:
            from email import Encoders as encoders
            
        content_type = content_type or mimetypes.guess_type(filename)[0] or "applcation/octet-stream"
        
        msg = self.new_message()
        msg.set_payload(content)
        msg.add_header('Content-Type', content_type)
        msg.add_header('Content-Disposition', 'attachment', filename=filename)
        
        if not content_type.startswith("text/"):
            encoders.encode_base64(msg)
            
        self.message.attach(msg) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:27,代码来源:utils.py

示例3: __init__

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def __init__(self, _data, _subtype='octet-stream',
                 _encoder=encoders.encode_base64, **_params):
        """Create an application/* type MIME document.

        _data is a string containing the raw applicatoin data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')
        MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
        self.set_payload(_data)
        _encoder(self) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:application.py

示例4: attach

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def attach(self, filename, content, content_type=None):
        if not self.multipart:
            msg = self.new_message()
            msg.add_header("Content-Type", "multipart/mixed")
            msg.attach(self.message)
            self.message = msg
            self.multipart = True
                        
        import mimetypes
        try:
            from email import encoders
        except:
            from email import Encoders as encoders
            
        content_type = content_type or mimetypes.guess_type(filename)[0] or "application/octet-stream"
        
        msg = self.new_message()
        msg.set_payload(content)
        msg.add_header('Content-Type', content_type)
        msg.add_header('Content-Disposition', 'attachment', filename=filename)
        
        if not content_type.startswith("text/"):
            encoders.encode_base64(msg)
            
        self.message.attach(msg) 
开发者ID:Naayouu,项目名称:Hatkey,代码行数:27,代码来源:utils.py

示例5: WOSendMail

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def WOSendMail(send_from, send_to, subject, text, files, server="localhost",
               port=587, username='', password='', isTls=True):
    msg = MIMEMultipart()
    msg['From'] = send_from
    msg['To'] = send_to
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject

    msg.attach(MIMEText(text))

    for f in files:
        part = MIMEBase('application', "octet-stream")
        part.set_payload(open(f, "rb").read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="{0}"'
                        .format(os.path.basename(f)))
        msg.attach(part)

    smtp = smtplib.SMTP(server, port)
    if isTls:
        smtp.starttls()

    smtp.sendmail(send_from, send_to, msg.as_string())
    smtp.quit() 
开发者ID:WordOps,项目名称:WordOps,代码行数:26,代码来源:sendmail.py

示例6: __init__

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def __init__(self, _data, _subtype='octet-stream',
                 _encoder=encoders.encode_base64, *, policy=None, **_params):
        """Create an application/* type MIME document.

        _data is a string containing the raw application data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')
        MIMENonMultipart.__init__(self, 'application', _subtype, policy=policy,
                                  **_params)
        self.set_payload(_data)
        _encoder(self) 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:24,代码来源:application.py

示例7: send_mail

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def send_mail(self, subject, message, files=None):

        if files is None:
            files = []

        msg = MIMEMultipart()
        msg['Date'] = formatdate(localtime=True)
        msg['Subject'] = subject

        msg.attach(MIMEText(message))

        # TODO files attachment max size
        if files is not None:
            for f in files:
                part = MIMEBase('application', "octet-stream")
                part.set_payload(open(f, "rb").read())
                encoders.encode_base64(part)
                part.add_header('Content-Disposition', 'attachment; filename="{0}"'.format(os.path.basename(f)))
                msg.attach(part)

        self.logger.debug('Sending mail to {0} {1}'.format(self.to_address, ' about {0}'.format(subject)))
        self.server.sendmail(self.from_username, self.to_address, msg.as_string())
        self.logger.debug('Mail was sent.') 
开发者ID:Pardus-LiderAhenk,项目名称:ahenk,代码行数:25,代码来源:mail_manager.py

示例8: attach_docs

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def attach_docs(*fns):
    """Adds multipart docs."""
    email = MIMEMultipart()
    for fn in fns:
        with open(fn, 'rb') as f:
            data = f.read()
        doc = MIMEBase('application', 'vnd.ms-word')
        doc.set_payload(data)
        encoders.encode_base64(doc)
        doc.add_header('Content-Disposition', 'attachment; filename="%s"' % fn)
        email.attach(doc)
    return email 
开发者ID:wdxtub,项目名称:deep-learning-note,代码行数:14,代码来源:4_generate_email.py

示例9: attach_files

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def attach_files(*fns):
    """
    Adds multipart files. Very basic. Can be made better
    by using multiple application types for MIMEBase object.
    """
    email = MIMEMultipart()
    for fn in fns:
        with open(fn, 'rb') as f:
            data = f.read()
        stuff = MIMEBase('application', 'octet-stream')
        stuff.set_payload(data)
        encoders.encode_base64(stuff)
        stuff.add_header('Content-Disposition', 'attachment; filename="%s"' % fn)
        email.attach(stuff)
    return email 
开发者ID:wdxtub,项目名称:deep-learning-note,代码行数:17,代码来源:4_generate_email.py

示例10: send_qq_mail

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def send_qq_mail(from_addr, password, to_addr, content, subject='', files=None, host=('smtp.qq.com', 465)):
    """这个一个邮箱发送函数.默认是qq邮箱

    :param from_addr: 发送方邮箱
    :param password: 填入发送方邮箱的授权码
    :param to_addr: 收件人为多个收件人,通过;为间隔的字符串,比如: xx@qq.com;yy@qq.com
    :param content: 正文
    :param subject: 主题
    :param files: 附加
    :param host: 邮件传输协议
    :return: bool类型.打印成功和失败
    """
    text = MIMEText(content, _charset='utf-8')
    m = MIMEMultipart()
    if files:
        import os
        from email import encoders
        file_name = os.path.basename(files)  # 获得文件名字
        file = MIMEApplication(open(files, 'rb').read())
        file.add_header('Content-Disposition', 'attachment', filename=('GBK', '', file_name))
        encoders.encode_base64(file)  # 解决文件名乱码问题
        m.attach(file)
    m['Subject'] = subject
    m['From'] = from_addr
    m['To'] = to_addr
    m.attach(text)
    server = None
    try:
        server = smtplib.SMTP_SSL(*host)  # 安全模式
        server.login(from_addr, password)  # 登陆
        server.sendmail(from_addr, to_addr, m.as_string())  # 发送
        return True
    except smtplib.SMTPException as e:
        print(e)
        return False
    finally:
        if not server:
            server.quit()


# jfciwswgxlmedjei9 
开发者ID:jtyoui,项目名称:Jtyoui,代码行数:43,代码来源:qq.py

示例11: add_attachment

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def add_attachment(self,filepath,filename=None):
        if filename == None:
            filename=os.path.basename(filepath)

        with open(filepath,'rb') as f:
            file=f.read()

        ctype, encoding = mimetypes.guess_type(filepath)
        if ctype is None or encoding is not None:ctype = "application/octet-stream"
        maintype, subtype = ctype.split('/', 1)

        if maintype == "text":
            with open(filepath) as f:file=f.read()
            attachment = MIMEText(file, _subtype=subtype)
        elif maintype == "image":
            with open(filepath,'rb') as f:file=f.read()
            attachment = MIMEImage(file, _subtype=subtype)
        elif maintype == "audio":
                with open(filepath,'rb') as f:file=f.read()
                attachment = MIMEAudio(file, _subtype=subtype)
        else:
                with open(filepath,'rb') as f:file=f.read()
                attachment = MIMEBase(maintype,subtype)
                attachment.set_payload(file)
                attachment.add_header('Content-Disposition', 'attachment', filename=filename)
                encoders.encode_base64(attachment)

        attachment.add_header('Content-Disposition', 'attachment', filename=filename)
        attachment.add_header('Content-ID',str(self.attachment_num))
        self.attachment_num+=1

        self.attachment_list.append(attachment) 
开发者ID:Aliencn,项目名称:Smail,代码行数:34,代码来源:Smail.py

示例12: get_attachment

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def get_attachment(bookpath, filename):
    """Get file as MIMEBase message"""
    calibrepath = config.config_calibre_dir
    if config.config_use_google_drive:
        df = gdriveutils.getFileFromEbooksFolder(bookpath, filename)
        if df:
            datafile = os.path.join(calibrepath, bookpath, filename)
            if not os.path.exists(os.path.join(calibrepath, bookpath)):
                os.makedirs(os.path.join(calibrepath, bookpath))
            df.GetContentFile(datafile)
        else:
            return None
        file_ = open(datafile, 'rb')
        data = file_.read()
        file_.close()
        os.remove(datafile)
    else:
        try:
            file_ = open(os.path.join(calibrepath, bookpath, filename), 'rb')
            data = file_.read()
            file_.close()
        except IOError as e:
            log.exception(e)
            log.error(u'The requested file could not be read. Maybe wrong permissions?')
            return None

    attachment = MIMEBase('application', 'octet-stream')
    attachment.set_payload(data)
    encoders.encode_base64(attachment)
    attachment.add_header('Content-Disposition', 'attachment',
                          filename=filename)
    return attachment


# Class for sending email with ability to get current progress 
开发者ID:janeczku,项目名称:calibre-web,代码行数:37,代码来源:worker.py

示例13: send_certificate

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def send_certificate(self, path, send_to):
        """
            Send each certificate from the configured email.
        """

        # Email info
        msg = MIMEMultipart()
        msg["From"] = self.email
        msg["To"] = send_to
        msg["Subject"] = u"Certificado"

        body = u"""Em anexo a este e-mail encontra-se o seu certificado de participação de um de nossos eventos.

        Qualquer problema, entre em contato respondendo a este e-mail ou procure-nos em:
        {address}
        Fone: {phone}
        """.format(
                    address=unicode(self.Config.get("Contact", "address")),
                    phone=unicode(self.Config.get("Contact", "phone"))
                  )
        msg.attach(MIMEText(unicode(body), 'plain', 'utf-8'))

        # Add the certificate file
        attachment = open(unicode(path), "rb")
        filename = os.path.basename(unicode(path))
        part = MIMEBase('application', 'octet-stream')
        part.set_payload(attachment.read())
        encoders.encode_base64(part)
        part.add_header(u'Content-Disposition',
                        "attachment; filename= %s" % filename)
        msg.attach(part)

        text = msg.as_string()
        # Send the email
        self.smtp_server.sendmail(self.email, send_to, text) 
开发者ID:juliarizza,项目名称:certificate_generator,代码行数:37,代码来源:mail.py

示例14: __init__

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def __init__(self, _audiodata, _subtype=None,
                 _encoder=encoders.encode_base64, **_params):
        """Create an audio/* type MIME document.

        _audiodata is a string containing the raw audio data.  If this data
        can be decoded by the standard Python `sndhdr' module, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify  the specific audio subtype via the
        _subtype parameter.  If _subtype is not given, and no subtype can be
        guessed, a TypeError is raised.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            _subtype = _whatsnd(_audiodata)
        if _subtype is None:
            raise TypeError('Could not find audio MIME subtype')
        MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
        self.set_payload(_audiodata)
        _encoder(self) 
开发者ID:glmcdona,项目名称:meddle,代码行数:31,代码来源:audio.py

示例15: __init__

# 需要导入模块: from email import encoders [as 别名]
# 或者: from email.encoders import encode_base64 [as 别名]
def __init__(self, _imagedata, _subtype=None,
                 _encoder=encoders.encode_base64, **_params):
        """Create an image/* type MIME document.

        _imagedata is a string containing the raw image data.  If this data
        can be decoded by the standard Python `imghdr' module, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify the specific image subtype via the _subtype
        parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            _subtype = imghdr.what(None, _imagedata)
        if _subtype is None:
            raise TypeError('Could not guess image MIME subtype')
        MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
        self.set_payload(_imagedata)
        _encoder(self) 
开发者ID:glmcdona,项目名称:meddle,代码行数:30,代码来源:image.py


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