我正在尝试使用email-templates软件包,但是遇到了问题。一切正常,直到我将路径从静态文件更改为url。从那时起,每当我尝试发送电子邮件时,它只会在浏览器中显示临时文件,而不是实际通过电子邮件发送任何内容。我尝试将其改回,但问题仍然存在。由于这是关于附件的,因此我假设这是一个nodemailer问题,而不是电子邮件模板问题。 这是我的代码:
const Email = require("email-templates");
email = new Email({
message: {
from: "pribehytest@seznam.cz"
},
// uncomment below to send emails in development/test env:
// send: true
transport: {
host: "smtp.seznam.cz",
port: 465,
secure: true,
auth: {
user: "mail",
pass: "password"
}
}
})
// this is in a different file
pdf.create(compiledPugInvoice({
// some locals
}), {format: "Letter"}).toFile("emails/newOrder/invoices/invoice" + orderID + ".pdf", (err, result) => {
if(err) next(err);
else{
cloudinary.uploader.upload("emails/newOrder/invoices/invoice" + orderID + ".pdf", (cloudinaryResult) => {
console.log(cloudinaryResult);
// send an email to the client
email
.send({
template: "newOrder",
message: {
to: req.body.email,
attachments: [
{
filename: "faktura.pdf",
path: cloudinaryResult.secure_url
}
]
},
locals: {
// some locals
}
})
.then(() => {
fs.unlink("emails/newOrder/invoices/invoice" + orderID + ".pdf", (err) => {
if(err) next(err);
}))
.catch(console.error);
});