Chinese Characters Included in Subject When GMail Sends Mail Can't Be Displayed Correctly

强颜欢笑 提交于 2019-12-08 13:35:50

问题


I send a mail in javascript via GMail API. If mail subject has Chinese Characters,it cant't display correctly in GMail Inbox.

And message has Chinese Characters no problem.

var email = '';
email =
    'Content-Type: multipart/mixed;boundary="foo_bar_baz"\r\n'+
    "To: " + $('#compose-to').val() + "\r\n" +
    "Subject: 这里是中文字符" +"\r\n\r\n";

email += "--foo_bar_baz\r\n" +
       "Content-Type: text/html;charset='UTF-8'\r\n" +
       "Content-Transfer-Encoding: 8bit\r\n";
email += "\r\n" + $('#compose-message').val()+"\r\n\r\n";

email += "--foo_bar_baz\r\n" +
    "Content-Type: application/pdf;attachment;filename=5678.pdf\r\n" +
    "Content-Transfer-Encoding: base64\r\n" +
    "Content-Disposition: attachment;filename=5678.pdf\r\n\r\n" +
    file_ + "\r\n\r\n";

var sendRequest = gapi.client.gmail.users.messages.send({
  'userId': 'me',
  'resource': {
    'raw': window.btoa(unescape(encodeURIComponent(email))).replace(/\+/g, '-').replace(/\//g, '_')
  }
});

回答1:


I add code '=?UTF-8?B? ?=' to subject string and it works. As follows.

var email = '';
email =
    'Content-Type: multipart/mixed;boundary="foo_bar_baz"\r\n'+
    "To: " + $('#compose-to').val() + "\r\n" +
    "Subject: =?UTF-8?B?"++window.btoa(unescape(encodeURIComponent('这里是中文字 
    符')))+"?=" +"\r\n\r\n";


来源:https://stackoverflow.com/questions/57212599/chinese-characters-included-in-subject-when-gmail-sends-mail-cant-be-displayed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!