Gmail主题中的西班牙字符问题(á,é,í,ó,ú,ñ) [英] Problems with Spanish Characters (á, é, í, ó, ú, ñ) in the Gmail subject

查看:284
本文介绍了Gmail主题中的西班牙字符问题(á,é,í,ó,ú,ñ)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助。也许这是一个非常简单的错误,但我解决不了。此代码非常适合创建Gmail草稿。但是我在西班牙文中遇到了问题:á,é,í,ó,ú,ñ。 HTML Body正常工作,它可以识别这些字符(á,é,í,ó,ú,ñ,ñ)。



我相信我需要将代码字符集= UTF-8在一些特殊的一面。

 函数createHTMLDraftInGmail(){

var forScope = GmailApp.getInboxUnreadCount() ; //需要授权范围
var htmlBody =< p>您好,我是一个HTML邮件< / p>< hr>;;
var raw ='From:Me< amit@labnol.org> \r\\\
'+
'致:您< hello@example.com.comgt; \r\ n'+
'主题:保存草稿消息\r\\\
'+
'Content-Type:text / html; charset = UTF-8 \r\\\
'+
'\r\\\
'+ htmlBody;

var draftBody =
Utilities.base64Encode(raw,Utilities.Charset.UTF_8).replace(/ \ // g,'_')。replace(/ \ + / g , ' - ');

var params = {
method:post,
contentType:application / json,
headers:{Authorization:Bearer+ ScriptApp .getOAuthToken()},
muteHttpExceptions:true,
payload:JSON.stringify({
message:{
raw:draftBody
}
})
};

var resp =
UrlFetchApp.fetch(https://www.googleapis.com/gmail/v1/users/me/drafts,params);
Logger.log(resp.getContentText());
}

问候,

解决方案

我做了一些测试,发现当你发送一封包含这些字符的电子邮件时,它会将以下内容添加到主题行中:

  =?ISO-8859-1] Q? ?= 

=?表示开始和?= 该行的结尾。 ISO-8859-1?引用字符集。我不确定 Q?



Q??= 你将拥有你的主题信息。所有的西班牙字符都必须进行编码,例如。 'ElNiño'(孩子)必须写成:'El Ni = F1o'。其中 = F1 对应于ñ'。 org / wiki / ISO / IEC_8859-1#Codepage_layoutrel =nofollow> ISO-8859-1 charset。

调查了一下,我还发现你可以在base64中编码主题字符串,并将下面一行添加到主题行:

  =?UTF-8?B?RWwgTmnDsW8 =?= 

在这种情况下, RWwgTmnDsW8 = 是由'ElNiño'编码的字符串。

第二种方法比第一种方法更容易(我在写完第一部分后发现它),尝试一下,看看它是否适用于您。

I need your help. Maybe it's a very simple error, but I can't solve it. This code works great in order to create a Gmail draft. But I have problems with the Spanish characters: á, é, í, ó, ú , ñ in the subject. The HTML Body works fine, it recognizes these characters (á, é, í, ó, ú, ñ).

I believe that I need to put the code "charset=UTF-8" in a some special side. What do you recommend?

function createHTMLDraftInGmail() {

 var forScope = GmailApp.getInboxUnreadCount(); // needed for auth scope
 var htmlBody = "<p>Hello, I am an HTML message</p><hr>";
 var raw = 'From: Me <amit@labnol.org>\r\n' +
        'To: You <hello@example.com.com>\r\n' +
        'Subject: Save Draft Message\r\n' +
        'Content-Type: text/html; charset=UTF-8\r\n' + 
        '\r\n' + htmlBody;

var draftBody = 
Utilities.base64Encode(raw,Utilities.Charset.UTF_8).replace(/\//g,'_').replace(/\+/g,'-');

var params = {
method      : "post",
contentType : "application/json",
headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions:true,
payload:JSON.stringify({
  "message": {
    "raw": draftBody
  }
})
};

var resp =
  UrlFetchApp.fetch("https://www.googleapis.com/gmail/v1/users/me/drafts", params);
 Logger.log(resp.getContentText());
 }

Greetings,

解决方案

I made some test and found that when you send an email with those characters, it adds the following to the subject line:

=?ISO-8859-1?Q?  ?=

The =? indicates the start and ?= the end of the line. The ISO-8859-1? makes reference to the charset. I'm not sure about the Q?.

Between the Q? and ?= you will have your subject message. All the spanish characters will have to be encoded, eg. 'El Niño' (the kid), would have to be written as: 'El Ni=F1o'. Where =F1 corresponds to the 'ñ' in the ISO-8859-1 charset.

Investigating a little bit more, I also found that you can encode the subject string in base64 and add the following line to the Subject line:

=?UTF-8?B?RWwgTmnDsW8=?=

In this case RWwgTmnDsW8= is the string encoded of 'El Niño'.

This second approach is easier than the first one (I found it after writing the first part), try it and see if it works for you.

这篇关于Gmail主题中的西班牙字符问题(á,é,í,ó,ú,ñ)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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