当前位置: 首页>>代码示例>>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;未经允许,请勿转载。