如何在firestore中实现多个nodemail sendMail函数



我在firestore中有两个文档引用,它们触发了sendMail函数"onCreate"。第一个功能很好,但第二个功能不好。为了区分两个sendMail函数,我将名称更改为sendMailxxx。我相信,这导致了这个错误。提供的错误为

类型错误:transportr.sendMailupfill不是函数

在exports.sendMailupfill.functions.firestore.document.on创建

在同一个index.js文件中定义两个sendMail函数的最佳方法是什么?

这里有代码,

// Send the transaction email  
exports.sendMail = functions.firestore.document('Companys/{companyid}/Transaction/{transactionid}').onCreate((snap, context) => {
const mailOptions = {
from: 'L App<report@sample.com>', // You can write any mail Address you want this doesn't effect anything,
to: snap.data().companyemailcf, // This mail address should be filled with any mail you want to read it,
bcc: 'admin@test.com',
subject: 'L Fuel , New Tranaction ',
html: `<h1>Confirmed Transaction</h1>
<p>

<b>Datetime: </b>${snap.data().datetime}<br>
<b>User: </b>${snap.data().user}<br>
<b>Vehicle: </b>${snap.data().vehicle}<br>
<b>Account: </b>${snap.data().account}<br>

</p>`
};

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
return
}
console.log('Message sent: ' + info.response);
});
});

//Send the up-fill email
exports.sendMailupfill = functions.firestore.document('Companys/{companyid}/Upfill/{upfillid}').onCreate((snap, context) => {

const mailOptions = {
from: 'L Fuel App<report@sample.com>',
to: snap.data().companyemailcf, // 
subject: 'L Fuel Record, New Tranaction ',
html: `<h1>Confirmed Bulk Tank Up-fill</h1>
<p>

<b>Up-fill date: </b>${snap.data().upfilldate}<br>
<b>Up-fill amount: </b>${snap.data().upfillamount}<br>
<b>Up-fill reference: </b>${snap.data().upfillreference}<br>
</p>`
};

transporter.sendMailupfill(mailOptions, (error, info) => {
if (error) {
console.log(error);
return
}
console.log('Message sent: ' + info.response);
});
}

);
不要将调用的名称更改为transporter.sendMail。只需更改导出函数的名称。

相关内容

  • 没有找到相关文章

最新更新