I'm trying to use the email-templates package but I ran into a problem. Everything was working fine until I changed the path from a static file to a url. From then, whenever I try to send an email, it just shows the temp file in the browser instead of actually emailing anything. I tried changing it back but the problem is still here. Since this is about the attachments, I'm assuming it's a nodemailer problem, not an email-templates problem. Here's my code:
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);
});