Gmail API - 明文自动换行 [英] Gmail API - plaintext word wrapping

查看:19
本文介绍了Gmail API - 明文自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Gmail API 发送电子邮件时,它会在正文中放置硬换行符,每行大约 78 个字符.可以在这里找到一个类似的问题.

When sending emails using the Gmail API, it places hard line breaks in the body at around 78 characters per line. A similar question about this can be found here.

我怎样才能停下来?我只是想通过 API 发送纯文本电子邮件而无需换行.当前的格式看起来很糟糕,尤其是在移动客户端上(在 Gmail 和 iOS 邮件应用上测试过).

How can I make this stop? I simply want to send plaintext emails through the API without line breaks. The current formatting looks terrible, especially on mobile clients (tested on Gmail and iOS Mail apps).

我尝试了以下标题:

内容类型:文本/纯文本;charset=UTF-8

Content-Transfer-Encoding:quoted-printable

我错过了什么吗?

根据 Mr.Rebot 的建议,我也尝试过,但没有成功:

As per Mr.Rebot's suggestion, I've also tried this with no luck:

内容类型:混合/替代

编辑 2: 这是我发送的消息的确切格式(尝试使用和不使用 quoted-printable 标头:

EDIT 2: Here's the exact format of the message I'm sending (attempted with and without the quoted-printable header:

From: Example Account <example1@example.com>
To: <example2@example.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Subject: This is a test!
Date: Tue, 18 Oct 2016 10:46:57 -GMT-07:00

Here is a long test message that will probably cause some words to wrap in strange places.

我获取此完整消息并对其进行 Base64 编码,然后使用以下 JSON 正文将其发布到 /gmail/v1/users/{my_account}/drafts/send?fields=id:

I take this full message and Base64-encode it, then POST it to /gmail/v1/users/{my_account}/drafts/send?fields=id with the following JSON body:

{
    "id": MSG_ID,
    "message": {
        "raw": BASE64_DATA
    }
}

推荐答案

您是否通过 quoted printable 编码器并将编码的内容值与标头一起发送或期望 API 为您编码?

Are you running the content through a quoted printable encoder and sending the encoded content value along with the header or expecting the API to encode it for you?

wikipedia 似乎您使用 = 少于 76 个字符作为任意行的最后一个字符,它们应该从结果中解码出来,恢复您的原始文本.

Per wikipedia it seems like if you add soft line breaks with = less than 76 characters apart as the last character on arbitrary lines, they should get decoded out of the result restoring your original text.

更新

尝试使用已引用可打印编码(base64 it)的内容发送此内容:

Try sending with this content whose message has been quoted-printable encoded (base64 it):

From: Example Account <example1@example.com>
To: <example2@example.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Subject: This is a test!
Date: Tue, 18 Oct 2016 10:46:57 -GMT-07:00

Here is a long test message that will probably cause some words to wrap in =
strange places.

这篇关于Gmail API - 明文自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆