问题
This is my actual output
This is my expected output
when a mail is sent with html table along with file attachment(like image, pdf, etc.), table format is not displayed in mail but content of table is displayed. But when I inspect mail body table is present. Problem is that its not shown in table format. But when mail sent with html table without attachment, table format is getting displayed in mail. How to fix it.
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);
})
I want html table to be highlighted in gmail irrespective of attachment is present or not.
来源:https://stackoverflow.com/questions/54018048/gmail-with-table-in-message-body-is-not-getting-displayed-in-mail-but-table-data