본문 바로가기
Tip

AWS SES: 이메일 발신자 이름 UTF8 인코딩

by chuckolet 2019. 4. 30.

Introduction

AWS SES를 사용해서 메일을 발송 할 때 Message 부분에는 Charset을 설정하는 부분이 있는데 Source부분에는 따로 그런 설정 없이 스트링만 보낼 수 있어서 한글 이름을 사용하려면 따로 인코딩을 했습니다.

 

Gmail에서 발신자 이름 한글 깨짐

구글링 해보니 아래 같은 답변이 있네요.

You would need to use MIME encoded-word syntax to use non-ASCII characters in the Source text. There's some additional discussion in the SES API reference:

In all cases, the email address must be 7-bit ASCII. If the text must contain any other characters, then you must use MIME encoded-word syntax (RFC 2047) instead of a literal string. MIME encoded-word syntax uses the following form: =?charset?encoding?encoded-text?=. For more information, see RFC 2047.

위 답변에 따르면 Source 부분에 ASCII characters 외의 다른 문자를 사용하려면 이메일에서 사용하는 Media-Type(MIME)라는 타입으로 변환해서 바꿔주어야 한다고 하는군요.

인코딩이나 MIME에 대해서 더 알고 싶으신 분들은 아래 첨부한 레퍼런스 링크를 참고해주시면 됩니다.

 

아래 커맨드로 변환에 필요한 라이브러리를 설치하고

npm i q-encoding utf8

 

아래 코드처럼 인코딩해서 사용하시면 됩니다.

var qencode = require('q-encoding');

var utf8 = require('utf8');

var MIME = (string) => '=?UTF-8?Q?' + qencode.encode(utf8.encode(string)) + '?=';

...

ses.sendEmail({ 
	... 
    Source: MIME(fromName) + ' <' + fromEmail + '>',
	...
}, ...

References

 

SES: UTF8 Chars in sender name of email · Issue #1585 · aws/aws-sdk-js

I'm trying to send emails from a sender name with characters not being in the 7-bit ASCII range. ses.sendEmail({ ... Source: fromName + ' <' + fromEmail + '>', ... }, ... ...

github.com

 

MIME이란 무엇인가?

MIME이란 무엇인가? MIME이란? Multipurpose Internet Mail Extensions의 약자로 간략히 말씀을 드리면 파일 변환을 뜻한다고할 수 있습니다. MIME는 이메일과 함께 동봉할 파일을 텍스트 문자로 전환해서 이메일..

server-talk.tistory.com

 

제 글이 도움이 되셨다면 간단하게 '공감', '댓글' 부탁드립니다!

 

 

댓글