当带有html表和文件附件(如图像,pdf等)的邮件一起发送时,表格式不会显示在邮件中,但会显示表的内容。但是当我检查邮件正文表是否存在时。问题是它没有以表格格式显示。但是,当使用不带附件的html表发送邮件时,表格式将显示在邮件中。如何解决。
let user = await db.model('User').findOne({ _id: userId });
let filepath = fs.readFileSync(req.file.path).toString('base64');
let from = user.crmOptions.email;
let raw = [
'MIME-Version: 1.0\n',
"to: ", req.body.to, "\n",
"from: ", from, "\n",
"cc: ", req.body.cc ? req.body.cc : '', "\n",
"bcc: ", req.body.bcc ? req.body.bcc : '', "\n",
"subject: ", req.body.subject ? req.body.subject : '', "\n",
"Content-Type: multipart/mixed; boundary=boundary_mail1\n\n",
"--boundary_mail1\n",
"Content-Type: multipart/alternative; boundary=boundary_mail2\n\n",
"--boundary_mail2\n",
"Content-Type: text/html; charset=UTF-8\n",
"Content-Transfer-Encoding: quoted-printable\n\n",
req.body.message = req.body.message ? req.body.message : '', "\n\n",
"--boundary_mail2--\n",
'--boundary_mail1\n',
`Content-Type: ${req.file.mimetype}\n`,
`Content-Disposition: attachment; filename="${req.file.filename}"\n`,
"Content-Transfer-Encoding: base64\n\n",
filepath, '\n',
'--boundary_mail1--',
].join('');
const id = 'me';
let options = {
url: "https://www.googleapis.com/upload/gmail/v1/users/" + id + "/messages/send?uploadType=multipart",
method: 'POST',
headers: {
'Authorization': `Bearer ${user.crmOptions.access_token}`,
'Content-Type': 'message/rfc822'
},
body: raw
};
await request(options).then(async body => {
console.log("Body: ", body);
}).catch(err => {
console.log("Error: ", err);
})
我希望html表以gmail突出显示,无论是否存在附件。