繁体   English   中英

使用 GMAIL API 发送 Email 和附件(超过 10 MB)在 Z9E13B69D1D2DA9347102ACAAAF75

[英]Send Email with attachment file (more than 10 MB) using GMAIL API in Javascript

How to Send Email with an attachment PDF file (more than 10 MB) using GMAIL API in Javascript. 我尝试使用 PDF 文件附件的一些代码并发送 email 如下。

const base64Data = 'Base64 PDF File string here (10 MB)'
const mixedB = 'mixedB';
const relatedB = 'relatedB';
const alternativeB = 'alternativeB';
const To = 'test@gmail.com'
const message = '<p>This is TEST EMAIL with PDF Attachment</p>'
const messageParts = [
  'From: ' + 'vijay@test.com',
  'To: ' + To,
  `Subject: This is Test Email`,
  'MIME-Version: 1.0',
  'Content-Type: multipart/mixed; boundary="' + mixedB + '"',
  '',
  '--' + mixedB,
  'Content-Type: multipart/related; boundary="' + relatedB + '"',
  '',
  '--' + relatedB,
  'Content-Type: multipart/alternative; boundary="' + alternativeB + '"',
  '',
  '--' + alternativeB,
  'Content-Type: text/html; charset=utf-8',
  '',
  message, // html content.
  '',
  '--' + alternativeB + '--',
  '',
  '--' + relatedB + '--',
  '',
  '--' + mixedB,
  'Content-Type: application/pdf;name="attachedFile.pdf"',
  'Content-Transfer-Encoding: base64',
  'Content-Disposition: attachment;filename="attachedFile.pdf"',
  '',
  base64Data, // base64 data of the file.
  '',
  '--' + mixedB + '--'
]

let aaa = messageParts.join('\r\n')

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

return sendRequest.execute();

我收到了一个 email,但附件的 PDF 文件在下载后无法打开。 看图片 代码中有什么愚蠢的错误吗? 请指导。

您应该进行可恢复上传而不是多部分上传。

上传选项中所述,可恢复上传更适合较大的文件:

可恢复上传:uploadType=resumable。 对于可靠的传输,对于较大的文件尤其重要。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM