Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mailgun发送内联图像,但不发送文本。[Python+Mailgun Api]_Python_Email_Mailgun_Inline Images - Fatal编程技术网

Mailgun发送内联图像,但不发送文本。[Python+Mailgun Api]

Mailgun发送内联图像,但不发送文本。[Python+Mailgun Api],python,email,mailgun,inline-images,Python,Email,Mailgun,Inline Images,我正在使用发送带有图像的电子邮件,电子邮件和图像到达收件人时没有问题,但是我在文本中发送的文本:测试一些邮枪的威严!它不会,它会将html:“正文的html版本”部分输出为正文文本 如何解决这个问题?当然,如果我在html行中添加我想要的文本,它看起来还可以,但我不知道这是否是正确的方法。我应该使用html部分作为正文文本并删除文本部分吗 谢谢首先,请注意用户手册中有一个错误。正确的代码段应如下所示: def send_simple_message(): return requests.

我正在使用发送带有图像的电子邮件,电子邮件和图像到达收件人时没有问题,但是我在文本中发送的文本:测试一些邮枪的威严!它不会,它会将html:“正文的html版本”部分输出为正文文本

如何解决这个问题?当然,如果我在html行中添加我想要的文本,它看起来还可以,但我不知道这是否是正确的方法。我应该使用html部分作为正文文本并删除文本部分吗


谢谢

首先,请注意用户手册中有一个错误。正确的代码段应如下所示:

def send_simple_message():
    return requests.post(
        "https://api.mailgun.net/v2/YOUR-DOMAIN/messages",
        auth=("api", "YOUR-KEY"),
        files={"inline":("image", open("/tmp/image.jpg"))},
        data={"from": "rob@example.com",
              "to": ["rob@example.com"],
              "subject": "Hello",
              "text": "Testing some Mailgun awesomness!",
              "html": '<html>Inline image here: <img src="cid:image"></html>'})
你看到了吗,无论用户看到的是哪一个版本,他都会得到相同的含义,只是受到他查看消息的媒介的限制


在另一种情况下,如果您选择不以“文本”和“html”两种格式发送相同的消息,则只能以其中一种格式发送。如果你只发送“html”,那么它将在大多数现代电子邮件阅读器上正确呈现,但在传统电子邮件阅读器上会乱说。如果您仅以“文本”形式发送,则在所有电子邮件阅读器上都可以阅读,但没有任何富格文本功能:粗体、斜体、内联图像等。

首先,请注意用户手册有一个错误。正确的代码段应如下所示:

def send_simple_message():
    return requests.post(
        "https://api.mailgun.net/v2/YOUR-DOMAIN/messages",
        auth=("api", "YOUR-KEY"),
        files={"inline":("image", open("/tmp/image.jpg"))},
        data={"from": "rob@example.com",
              "to": ["rob@example.com"],
              "subject": "Hello",
              "text": "Testing some Mailgun awesomness!",
              "html": '<html>Inline image here: <img src="cid:image"></html>'})
你看到了吗,无论用户看到的是哪一个版本,他都会得到相同的含义,只是受到他查看消息的媒介的限制


在另一种情况下,如果您选择不以“文本”和“html”两种格式发送相同的消息,则只能以其中一种格式发送。如果你只发送“html”,那么它将在大多数现代电子邮件阅读器上正确呈现,但在传统电子邮件阅读器上会乱说。如果您仅以“文本”形式发送,则所有电子邮件阅读器都可以阅读,但不会有任何富格文本功能:粗体、斜体、内联图像等。

Rob非常感谢您的分析我从您那里学到了一些东西,非常感谢,Rob非常感谢你的分析我从你那里学到了一些东西,我很感激,我看到了我的电子邮件的来源,你是对的,它确实是对的。
text='''Our sale prices are VERY LOW this weekend.
        Visit http://sales.example.com.''',
html='''<html>
        <img src="cid:logo.jpg"/>
        Our sale prices are <b>very low</b> this weekend.
        Visit <a href="http://sales.example.com">our website!</a>
        </html>'''