【问题标题】:How do you implement multiple nodemail sendMail functions in firestore?如何在 firestore 中实现多个 nodemail sendMail 功能?
【发布时间】: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


    【解决方案1】:

    请勿将呼叫名称更改为transporter.sendMail。只需更改导出函数的名称即可。

    【讨论】:

    • 很高兴它成功了。在 Stack Overflow 上,习惯上使用左侧的复选标记按钮将有用的答案视为正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2022-07-28
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    相关资源
    最近更新 更多