텍스트 대치 하다가 to, name 으로 한국어가 들어갔을 때 UTF-8로 인코딩 되지 않아 오류가 발생한 경우입니다. 

{ 
	"to": ["example@example.com", "example@example.com"]
	, "sub": {
		"%name%": ["테스트", "테테"] 
	} 
}

A message was received from this address by our systems that had errors in the SMTPAPI header, and cannot be processed due to the following:

 - invalid JSON

If you require assistance in working with the SendGrid API, please contact us at support@sendgrid.com

 


아래 구문으로 encodeText 처리하여 넘겨주면 정상적으로 메일 발송 성공을 확인할 수 있습니다.

message.addHeader("X-SMTPAPI", MimeUtility.encodeText(smtpJson));


Multipart multipart = new MimeMultipart("alternative");
BodyPart part = new MimeBodyPart();
message.addHeader("X-SMTPAPI", MimeUtility.encodeText(smtpJson));
part.setContent(content, "text/html; charset=utf-8");
multipart.addBodyPart(part);
message.setContent(multipart);

 

 

+ Recent posts