當前位置: 首頁>>代碼示例>>Python>>正文


Python MIMEText.set_payload方法代碼示例

本文整理匯總了Python中email.mime.text.MIMEText.set_payload方法的典型用法代碼示例。如果您正苦於以下問題:Python MIMEText.set_payload方法的具體用法?Python MIMEText.set_payload怎麽用?Python MIMEText.set_payload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.mime.text.MIMEText的用法示例。


在下文中一共展示了MIMEText.set_payload方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _create_mime_attachment

# 需要導入模塊: from email.mime.text import MIMEText [as 別名]
# 或者: from email.mime.text.MIMEText import set_payload [as 別名]
def _create_mime_attachment(self, content, mimetype):
        """
        Converts the content, mimetype pair into a MIME attachment object.

        If the mimetype is message/rfc822, content may be an
        email.Message or EmailMessage object, as well as a str.
        """
        basetype, subtype = mimetype.split('/', 1)
        if basetype == 'text':
            encoding = self.encoding or settings.DEFAULT_CHARSET
            attachment = SafeMIMEText(content, subtype, encoding)
        elif basetype == 'message' and subtype == 'rfc822':
            # Bug #18967: per RFC2046 s5.2.1, message/rfc822 attachments
            # must not be base64 encoded.
            if isinstance(content, EmailMessage):
                # convert content into an email.Message first
                content = content.message()
            elif not isinstance(content, Message):
                # For compatibility with existing code, parse the message
                # into an email.Message object if it is not one already.
                content = message_from_string(content)

            attachment = SafeMIMEMessage(content, subtype)
        else:
            # Encode non-text attachments with base64.
            attachment = MIMEBase(basetype, subtype)
            attachment.set_payload(content)
            Encoders.encode_base64(attachment)
        return attachment 
開發者ID:prakharchoudhary,項目名稱:Scrum,代碼行數:31,代碼來源:message.py

示例2: set_payload

# 需要導入模塊: from email.mime.text import MIMEText [as 別名]
# 或者: from email.mime.text.MIMEText import set_payload [as 別名]
def set_payload(self, payload, charset=None):
        if charset == 'utf-8':
            has_long_lines = any(
                len(l.encode('utf-8')) > RFC5322_EMAIL_LINE_LENGTH_LIMIT
                for l in payload.splitlines()
            )
            # Quoted-Printable encoding has the side effect of shortening long
            # lines, if any (#22561).
            charset = utf8_charset_qp if has_long_lines else utf8_charset
        MIMEText.set_payload(self, payload, charset=charset) 
開發者ID:alexsukhrin,項目名稱:django,代碼行數:12,代碼來源:message.py


注:本文中的email.mime.text.MIMEText.set_payload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。