Email 尽管添加了触发器,但无法部署Googlecloud函数

Email 尽管添加了触发器,但无法部署Googlecloud函数,email,firebase,google-cloud-functions,sendgrid,sendgrid-api-v3,Email,Firebase,Google Cloud Functions,Sendgrid,Sendgrid Api V3,我有下面的云功能,它试图在新用户注册时使用sendgrid发送电子邮件。这是原始firebase repo的一个修改版本,介绍了如何使用NodeEmailer发送电子邮件。在没有sendgrid功能的情况下,这在早期运行良好。因此,您在下面看到的是经过大量修改的代码版本 'use strict'; const functions = require('firebase-functions'); const nodemailer = require('nodemailer'); const SE

我有下面的云功能,它试图在新用户注册时使用sendgrid发送电子邮件。这是原始firebase repo的一个修改版本,介绍了如何使用NodeEmailer发送电子邮件。在没有sendgrid功能的情况下,这在早期运行良好。因此,您在下面看到的是经过大量修改的代码版本

'use strict';

const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const SEND_GRID_API_KEY = functions.config().sengrid.key


const sgMail = require('@sengrid/mail');
sgMail.setApiKey(SEND_GRID_API_KEY);




// Your company name to include in the emails
// TODO: Change this to your app or company name to customize the email sent.
const APP_NAME = 'Asia Rubber';

// [START sendWelcomeEmail]
/**
 * Sends a welcome email to new user.
 */
// [START onCreateTrigger]
exports.sendWelcomeEmail = functions.auth.user().onCreate((event) => {
  // [END onCreateTrigger]
  // [START eventAttributes]
  const user = event.data; // The Firebase user.

  const email = user.email; // The email of the user.
  const displayName = user.displayName; // The display name of the user.
  // [END eventAttributes]

  return sendWelcomeEmail(email, displayName);
});
// [END sendWelcomeEmail]

// [END sendByeEmail]

// Sends a welcome email to the given user.
function sendWelcomeEmail(email, displayName) {
  const msg = {
    from: `${APP_NAME} <Welcome@rubber.asia>`,
    to: email,
    subject: 'Welcome to ${APP_NAME}!',


    //custom templates
    templateId: 'e3978a51-5343-4b3a-9128-8c4a493f265e'
  };
  return sgMail.send(msg)
  .then( () => console.log('email sent'))
.catch(err => console.log(err))
}
顺便说一句,密钥没有引号

我做错了什么?
一般来说,代码有什么问题吗?Tks

您的云函数有一个小的输入错误。您正在尝试访问属性
sengrid
(在
send
中缺少
d

正确的代码行应该是:


const SEND\u GRID\u API\u KEY=functions.config().sendgrid.KEY
您的云函数有一个小的输入错误。您正在尝试访问属性
sengrid
(在
send
中缺少
d

正确的代码行应该是:


const SEND\u GRID\u API\u KEY=functions.config().sendgrid.KEY

不仅在那里,在其他地方也很少。但在更正并部署后,我无法收到任何电子邮件@JackyBoi这听起来是另一个问题。我将投票以打字错误结束这个问题(在类似情况下,不太可能有人会找到你的问题),我建议你打开一个新问题,详细说明问题的细节。请非常具体地说明正在发生的事情,否则没有人能够提供帮助。谢谢你发现这一点,不仅仅是在那里。其他地方也很少。但在更正并部署后,我无法收到任何电子邮件@JackyBoi这听起来是另一个问题。我将投票以打字错误结束这个问题(在类似情况下,不太可能有人会找到你的问题),我建议你打开一个新问题,详细说明问题的细节。请非常具体地说明正在发生的事情,否则没有人能够提供帮助。
PS E:\Cloudfunctions\erubberFunctions\functions> firebase deploy --only functions

=== Deploying to 'erubber'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint E:\Cloudfunctions\erubberFunctions\functions
> eslint .


E:\Cloudfunctions\erubberFunctions\functions\index.js
  79:14  warning  Unexpected template string expression  no-template-curly-in-string

✖ 1 problem (0 errors, 1 warning)

+  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
+  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'key' of undefined
    at Object.<anonymous> (E:\Cloudfunctions\erubberFunctions\functions\index.js:5:53)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at C:\Users\bhara\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:18:11
    at Object.<anonymous> (C:\Users\bhara\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:38:3)
firebase functions:config:set sendgrid.key=SG.YOUR_API_KEY