如何通过 Gmail API 在 JavaScript 中发送带有附件和消息的邮件
How to send mail with attachment and message in JavaScript via Gmail API
我可以发送附件,但是我不能发送附件和消息
添加消息发送失败
function sendMessage(message, callback)
{
var email =
"To: " + $('#compose-to').val() + "\r\n" +
"Subject: " + $('#compose-subject').val() + "\r\n" +
'Content-Transfer-Encoding: base64\r\n' +
'Content-Type: text/html; charset="UTF-8"\r\n' +
"" +
message+
"\r\n\r\n" +
"--foo_bar_baz\r\n" +
"Content-Type: image/png\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Disposition: attachment\r\n\r\n" +
file_ + "\r\n\r\n";
var sendRequest = gapi.client.gmail.users.messages.send({
'userId': 'me',
'resource': {
'raw': window.btoa(unescape(encodeURIComponent(email))).replace(/\+/g, '-').replace(/\//g, '_')
}
});
return sendRequest.execute(callback);
}
希望通过 gmail api
在 javascript 中发送带有附件和消息的邮件
出于文档目的发布答案。
根据 file upload documentation,有必要将 Content-Type
更改为 multipart/mixed
。大多数文件都需要此设置,因为它是在 Gmail API.
中添加附件的方式
我可以发送附件,但是我不能发送附件和消息
添加消息发送失败
function sendMessage(message, callback)
{
var email =
"To: " + $('#compose-to').val() + "\r\n" +
"Subject: " + $('#compose-subject').val() + "\r\n" +
'Content-Transfer-Encoding: base64\r\n' +
'Content-Type: text/html; charset="UTF-8"\r\n' +
"" +
message+
"\r\n\r\n" +
"--foo_bar_baz\r\n" +
"Content-Type: image/png\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Disposition: attachment\r\n\r\n" +
file_ + "\r\n\r\n";
var sendRequest = gapi.client.gmail.users.messages.send({
'userId': 'me',
'resource': {
'raw': window.btoa(unescape(encodeURIComponent(email))).replace(/\+/g, '-').replace(/\//g, '_')
}
});
return sendRequest.execute(callback);
}
希望通过 gmail api
在 javascript 中发送带有附件和消息的邮件出于文档目的发布答案。
根据 file upload documentation,有必要将 Content-Type
更改为 multipart/mixed
。大多数文件都需要此设置,因为它是在 Gmail API.