<bdo id='niTNv'></bdo><ul id='niTNv'></ul>

    <tfoot id='niTNv'></tfoot>
    1. <legend id='niTNv'><style id='niTNv'><dir id='niTNv'><q id='niTNv'></q></dir></style></legend>

    2. <small id='niTNv'></small><noframes id='niTNv'>

      <i id='niTNv'><tr id='niTNv'><dt id='niTNv'><q id='niTNv'><span id='niTNv'><b id='niTNv'><form id='niTNv'><ins id='niTNv'></ins><ul id='niTNv'></ul><sub id='niTNv'></sub></form><legend id='niTNv'></legend><bdo id='niTNv'><pre id='niTNv'><center id='niTNv'></center></pre></bdo></b><th id='niTNv'></th></span></q></dt></tr></i><div id='niTNv'><tfoot id='niTNv'></tfoot><dl id='niTNv'><fieldset id='niTNv'></fieldset></dl></div>
    3. 带有正文内容的 Python 电子邮件多部分

      时间:2023-07-03

      <legend id='NuyVh'><style id='NuyVh'><dir id='NuyVh'><q id='NuyVh'></q></dir></style></legend>
        <bdo id='NuyVh'></bdo><ul id='NuyVh'></ul>

        <small id='NuyVh'></small><noframes id='NuyVh'>

          <tfoot id='NuyVh'></tfoot>

                  <tbody id='NuyVh'></tbody>
                <i id='NuyVh'><tr id='NuyVh'><dt id='NuyVh'><q id='NuyVh'><span id='NuyVh'><b id='NuyVh'><form id='NuyVh'><ins id='NuyVh'></ins><ul id='NuyVh'></ul><sub id='NuyVh'></sub></form><legend id='NuyVh'></legend><bdo id='NuyVh'><pre id='NuyVh'><center id='NuyVh'></center></pre></bdo></b><th id='NuyVh'></th></span></q></dt></tr></i><div id='NuyVh'><tfoot id='NuyVh'></tfoot><dl id='NuyVh'><fieldset id='NuyVh'></fieldset></dl></div>

                本文介绍了带有正文内容的 Python 电子邮件多部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我无法在 python 中发送带有正文的电子邮件作为多部分电子邮件.我所做的一切都导致所有内容都作为附件,我无法让文本或 html 显示在正文中.

                I can't send an e-mail in python with a body as a multipart email. Everything I've tried has resulted in all of the content as attachments, and I can't get the text or html to show up in the body.

                msg = MIMEMultipart()
                if msg_mime_type == 'text' or not msg_mime_type:
                    new_body = MIMEText(body, 'text')
                elif msg_mime_type == 'image':
                    new_body = MIMEImage(body)
                elif msg_mime_type == 'html':
                    new_body = MIMEText(body, 'html')
                new_body.add_header('Content-Disposition', 'inline', filename='body')
                msg.set_payload(new_body) #also tried msg.attach(new_body)
                

                我需要使用 Multipart 以便我还可以添加附件,但为了简单起见,我保留了该代码.

                I need to use a Multipart so that i can also add attachments, but I kept that code out for simplicity.

                推荐答案

                您需要指定零件是彼此的替代品,例如multipart/alternative mime 类型:

                You need to specify that the parts are alternatives of one another, e.g. the multipart/alternative mime type:

                msg = MIMEMultipart('alternative')
                

                默认为混合;请参阅电子邮件库示例.

                请注意,要创建包含附件和替代 (HTML/CSS) 选项的电子邮件,您需要有一个包含 alternative<的顶级 multipart/related 容器/code> 部分作为第一个条目.

                Note that to create an email with both attachments and an alternative (HTML / CSS) option you'll need to have a top-level multipart/related container that contains the alternative parts as the first entry.

                这篇关于带有正文内容的 Python 电子邮件多部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

              • <legend id='oO8nw'><style id='oO8nw'><dir id='oO8nw'><q id='oO8nw'></q></dir></style></legend>
                <tfoot id='oO8nw'></tfoot>
                1. <i id='oO8nw'><tr id='oO8nw'><dt id='oO8nw'><q id='oO8nw'><span id='oO8nw'><b id='oO8nw'><form id='oO8nw'><ins id='oO8nw'></ins><ul id='oO8nw'></ul><sub id='oO8nw'></sub></form><legend id='oO8nw'></legend><bdo id='oO8nw'><pre id='oO8nw'><center id='oO8nw'></center></pre></bdo></b><th id='oO8nw'></th></span></q></dt></tr></i><div id='oO8nw'><tfoot id='oO8nw'></tfoot><dl id='oO8nw'><fieldset id='oO8nw'></fieldset></dl></div>

                      <tbody id='oO8nw'></tbody>

                      <small id='oO8nw'></small><noframes id='oO8nw'>

                        <bdo id='oO8nw'></bdo><ul id='oO8nw'></ul>