如何使用Node.js中的Gmail API发送带有附件的电子邮件? [英] How to send an email with attachment using Gmail API in Node.js?
本文介绍了如何使用Node.js中的Gmail API发送带有附件的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Node.js的新手,我正在尝试使用Gmail API创建一个邮箱,除了在电子邮件中上传附件之外,一切都很正常。我找到了使用Java、Python和C#的示例,但我找不到任何有关NODE的文档。 如有任何提示,我们将不胜感激。
以下是我的代码:
function makeBody(to, from, subject, message) {
var str = ["Content-Type: multipart/mixed; charset="UTF-8"
",
"MIME-Version: 1.0
",
"Content-Transfer-Encoding: 7bit
",
"to: ", to, "
",
"from: ", from, "
",
"subject: ", subject, "
",
message,
file
].join('');
var encodedMail = new Buffer(str).toString("base64").replace(/+/g, '-').replace(///g, '_');
return encodedMail;
}
function sendMessage(auth) {
var raw = makeBody(tap, 'me', response.subject, response.content, response.files);
gmail.users.messages.send({
auth: auth,
userId: 'me',
resource: {
raw: raw
}
}, function (err, response) {
if (err) {
console.log('Error ' + err);
return;
}
if (response) {
res.sendFile(__dirname + '/boite.html')
}
});
}
推荐答案
Creating messages with attachments中有相关说明:
创建带有附件的邮件与创建任何其他邮件类似,但将文件作为多部分MIME邮件上载的过程取决于编程语言。有关NodeJS示例参考,请选中SO Post。
这篇关于如何使用Node.js中的Gmail API发送带有附件的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文