繁体   English   中英

错误:内部 firebase 函数,与 nodemailer 一起使用时

[英]Error:INTERNAL firebase functions ,when using it with nodemailer

const transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: 'xxxxxx@gmail.com', pass: 'xxxxxxxx' } , tls: { rejectUnauthorized: false }, }); exports.sendMail=functions.https.onCall((req,res)=>{ cors(req,res,()=>{ const email=JSON.parse(req.email) const mailOptions = { from: 'xxxxxxxxx@gmail.com', to: email, subject: 'Invitation to register your profile in xxxxxxx solutions', text: `http://xxxxxx/xxxxxxxx` }; return transporter.sendMail(mailOptions, function(error, info){ if (error) { return res.send(error); } return res.send("Email sent") }); }) })

这很可能是因为你:

因此,您应该更改为HTTP Cloud Function ,如下所示:

  exports.sendMail=functions.https.onCall((req,res)=>{
      cors(req,res,()=>{

        const email=JSON.parse(req.email)
          const mailOptions = {
            from: 'xxxxxxxxx@gmail.com',
            to: email,
            subject: 'Invitation to register your profile in xxxxxxx solutions',
            text: `http://xxxxxx/xxxxxxxx`
          };

          transporter.sendMail(mailOptions)
          .then(() => {
              res.send("Email sent");
          })
          .catch(error => {
              console.log(error);
              res.status(500).send(error);
          });

      })
  })

或者按如下方式修改您的 Callable Cloud Function:

exports.addMessage = functions.https.onCall((data, context) => {
          const email = data.email;
  
          const mailOptions = {
            from: 'xxxxxxxxx@gmail.com',
            to: email,
            subject: 'Invitation to register your profile in xxxxxxx solutions',
            text: `http://xxxxxx/xxxxxxxx`
          };

          return transporter.sendMail(mailOptions)
          .then(() => {
              return {result: "Email sent"};
          })
          .catch(error => {
              console.log(error);
              throw new functions.https.HttpsError('interna', error.message);
          });
});

此外,请参阅此处如何从您的客户端调用 Callable CF。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM