Gmail API not respecting UTF encoding in subject

前端 未结 3 764
不思量自难忘°
不思量自难忘° 2021-01-18 19:29

In an app I\'m helping develop we\'ve added in the ability for a user to invite other users and personalize the invitation email, and then send it via Gmail\'s APIs. I\'m en

相关标签:
3条回答
  • 2021-01-18 19:56

    Tested the solution of @Oboo Chin and it's currently working.

    For PHP you could use:

    $subject = '=?utf-8?B?' . base64_encode( $subject ) . '?=';
    
    0 讨论(0)
  • 2021-01-18 19:58

    I ran into the same issue and I get the following information:Using UTF-8 charactors in an e-mail mail subject.

    So I replace my subject with:=?utf-8?B?${convertToBase64(subject)}?=,it works well.

    the ${} is an variable template, if you want to set Нык ан мюндй конвынёры as subject,it will seems like this:

    =?utf-8?B?0J3Ri9C6INCw0L0g0LzRjtC90LTQuSDQutC-0L3QstGL0L3RkdGA0Ys?=

    0 讨论(0)
  • By the RFC Standard, Email subject MUST be in US ASCII (7-bit).

    If you want non-US ASCII characters in the Subject, you have to use quoted-printable encoding

    So your

    Subject: Нык ан мюндй конвынёры
    

    must become

    Subject: =?iso-8859-1?Q?=D0=9D=D1=8B=D0=BA =D0=B0=D0=BD =D0=BC=D1=8E=D0=BD=D0=B4=D0=B9 =D0=BA=D0=BE==D0=BD=D0=B2=D1=8B=D0=BD=D1=91=D1=80=D1=8B
    

    Edit Updated in response to the comment:

    RFC 822/RFC2822 (https://www.ietf.org/rfc/rfc0822.txt) Section 2.2 Header Fields says:

    Header fields are lines composed of a field name, followed by a colon (":"), followed by a field body, and terminated by CRLF. A field name MUST be composed of printable US-ASCII characters (i.e., characters that have values between 33 and 126, inclusive), except colon. A field body may be composed of any US-ASCII characters, except for CR and LF. However, a field body may contain CRLF when used in header "folding" and "unfolding" as described in section 2.2.3. All field bodies MUST conform to the syntax described in sections 3 and 4 of this standard.

    US-ASCII is referred to the original 7-bit ASCII encoding (0-127).

    0 讨论(0)
提交回复
热议问题