【发布时间】:2020-08-06 16:45:46
【问题描述】:
我在 firestore 中有 2 个文档引用,它们触发了 sendMail 函数“onCreate”。第一个功能完美,但第二个没有。为了区分两个sendMail 函数,我将名称更改为sendMailxxx。我相信这导致了错误。提供的错误是
TypeError: transporter.sendMailupfill 不是函数
在exports.sendMailupfill.functions.firestore.document.onCreate
在同一个 index.js 文件中定义 2 个 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);
});
}
);
【问题讨论】:
标签: javascript google-cloud-firestore google-cloud-functions