Google apps script 在Google Apps脚本中创建电子邮件-无法创建特殊字符,如äöü;
我对下面的脚本有一个问题Google apps script 在Google Apps脚本中创建电子邮件-无法创建特殊字符,如äöü;,google-apps-script,email,Google Apps Script,Email,我对下面的脚本有一个问题 function doGet() { //Create draft email var body = "Project ö"; var subject = "Subject ö"; var forScope = GmailApp.getInboxUnreadCount(); // needed for auth scope var raw = 'Subject: ' + subject + '\n' +
function doGet() {
//Create draft email
var body = "Project ö";
var subject = "Subject ö";
var forScope = GmailApp.getInboxUnreadCount(); // needed for auth scope
var raw =
'Subject: ' + subject + '\n' +
'To: ' + "test@test.com" + '\n' +
'Content-Type: multipart/alternative; boundary=1234567890123456789012345678\n' +
'' + body + '\n' +
'--1234567890123456789012345678--\n';
var draftBody = Utilities.base64Encode(raw, Utilities.Charset.UTF_8);
var params = {method:"post",
contentType: "application/json",
headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions:true,
payload:JSON.stringify({
"message": {
"raw": draftBody
}
})
};
}
问题在于,德语中一些重要的特殊字符(“ä,ö,ü…”)没有正确地传输到生成的草稿电子邮件中
在草稿电子邮件中,字符“ö”被转换为“Ô。主体和主体是一样的
如何告诉Google Apps Script创建正确的字符?以下是一个通过将短语
德语(“ä,ö,ü…”)发送给我自己而收到的原始电子邮件正文示例:
MIME-Version: 1.0
Reply-To: me@example.com
Sender: me@example.com
Received: by x.x.x.x with HTTP; Mon, 21 Dec 2015 20:29:36 -0800 (PST)
Date: Mon, 21 Dec 2015 23:29:36 -0500
Delivered-To: me@example.com
X-Google-Sender-Auth: F53iraIGVkzcvVsK_xQusL1FB9Q
Message-ID: <CADiaKr4qDq8Anp4C0BymXC411nc0LtcVMrhTrQ6qErO00hB4CQ@mail.gmail.com>
Subject: german
From:Me <me@example.com>
To: Me <me@example.com>
Content-Type: multipart/alternative; boundary=94eb2c06bef09d6d1c0527750dfe
--94eb2c06bef09d6d1c0527750dfe
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
German language ("=C3=A4, =C3=B6, =C3=BC ...")
--94eb2c06bef09d6d1c0527750dfe
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:arial,he=
lvetica,sans-serif"><span style=3D"color:rgb(34,36,38);font-family:Arial,&#=
39;Helvetica Neue',Helvetica,sans-serif;font-size:15px;line-height:19.5=
px">=C2=A0German language ("=C3=A4, =C3=B6, =C3=BC ...")</span><b=
r></div></div>
--94eb2c06bef09d6d1c0527750dfe--
假设您只发送纯文本电子邮件。如果您同时发送一个HTML节,它还需要自己的内容类型
元标记,如果您需要另一种编码,这可能会有所不同。检查另一个问题:尝试使用实用程序。base64EncodeWebSafe
。base64EncodeWebSafe没有任何区别。@Gerardo:你说得对。它的工作原理与所描述的一样。非常感谢你!!!我应该如何/在哪里设置字符集?。我想我已经设置好了:draftBody=Utilities.base64Encode(raw,Utilities.Charset.utf8)
您需要与读者的电子邮件客户端沟通他们需要使用什么编码来解释邮件,这是作为电子邮件相关部分的内容类型
元数据的一部分完成的。