當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。