자바 스크립트에서 Gmail API를 사용하여 HTML 본문 및 ~ 100KB PDF 첨부 파일을 보내면 첨부 파일이 발신자의 Gmail 전송 메일에 첨부 된 것으로 올바르게 표시됩니다. 폴더에 있지만받는 사람의 메시지에는 나타나지 않습니다.Gmail API와 함께 보낸 메시지의 첨부 파일이 누락되어 있지만 수신자 만 수신
는 API 호출하는 POST
에 :
https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=media
API로 전송 된 요청 본문은 다음과 같습니다
{
"headers": {
"Authorization": "Bearer authToken-removedForThisPost"
},
"method": "POST",
"contentType": "message/rfc822",
"contentLength": 134044,
"payload": "exampleBelow",
"muteHttpExceptions": true
}
이 페이로드는 모습입니다 같은 :
MIME-Version: 1.0
To: =?utf-8?B?TWlrZSBD?=<[email protected]>
CC: =?utf-8?B?TWlrZSBD?=<[email protected]>
BCC: =?utf-8?B??=<[email protected]>
From: =?utf-8?B?TWlrZSBxWXsd2lr?=<[email protected]>
Subject: =?utf-8?B?subjectLine-removedForThisPost?=
Content-Type: multipart/alternative; boundary=__boundary__
--__boundary__
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
base64EncodedStringHere-removedForThisPost
--__boundary__
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64
base64EncodedStringHere-removedForThisPost
--__boundary__
Content-Type: application/pdf; name="File Name.pdf"
Content-Disposition: attachment; filename="File Name.pdf"
Content-Transfer-Encoding: base64
base64EncodedStringHere-removedForThisPost
--__boundary__--
참고 : Gmail API Uploading Attachments documentation에는 간단한 첨부 파일 (5MB 미만)을 업로드 할 때 Content-Length
이 필요합니다. 내 코드가 PDF 첨부 파일 총 바이트 수의 정수 값을 생성하도록 만들었습니다. 그러나 페이로드에는 Content-Length
이 포함되어 있지 않습니다.
메시지의 내용 유형을 multipart/mixed
으로 변경하려고 시도했습니다. 이는 PDF 첨부 파일이받는 사람의 메시지에 올바르게 첨부되어 있지만 HTML 본문이 일반 텍스트 (HTML 태그 이 표시되어 있으며 HTML로 렌더링 된 HTML 컨텐트가 포함 된 noname.html이라는 추가 첨부 파일이 있습니다.
받는 사람의 메시지에있는 전자 메일에 HTML 렌더링 본문과 PDF 첨부 파일이 모두 포함되도록해야합니다.
업데이트 : 원시 이메일 메시지의 예는 here입니다. 은 메시지가 왼쪽에 있고 은 메시지가 오른쪽에 있습니다.
당신은 ("__ 경계 __"='경계') 당신의 경계를 인용 최종 boudnary를 사용하여를 시도 ('--__ 경계 __--')? [** this ** ** (http://pastebin.com/SRZjEGfT)와 같은 무언가를 시도해보고 작동하는지 확인하십시오. – Tholle
내 페이로드 DID에'--__ boundary __--'의 최종 경계가 포함되어 있음을 알았지 만 console.log 메시지가 super long 첨부 base64 문자열로 인해 잘 렸기 때문에 여기에 붙여 넣었을 때 잘립니다. 큰 따옴표에 관해서는 첫 번째 Content-Type : 줄에 추가했지만 동작을 전혀 변경하지 않았습니다. – mike