以下是发送欢迎电子邮件的javascript:
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const userID = firestore.auth().currentUser.getId();
exports.sendWelcomeEmail =
functions.firestore.document('Users/{userID}').onCreate(async event => {
const name = event.data.data().name;
const email = event.data.data().email;
return sendWelcomeEmail(email, name);
})
function sendWelcomeEmail(email, name) {
const mailOptions = {
from: `${APP_NAME} <jagdish.choudhary@iitgn.ac.in>`,
to: email,
};
mailOptions.subject = `Welcome to ${APP_NAME}!`;
mailOptions.text = `Hey ${name || ''}! Welcome to ${APP_NAME}. I hope
you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
return console.log('New welcome email sent to:', email);
});
}
我有像用户一样的firestore数据库&gt; userID&gt;姓名,电子邮件。
请帮助我。
答案 0 :(得分:2)
正如@ArnavRao所说,你应该像你一样检索数据。它接缝正确,你不需要上面的这一行:const userID = firestore.auth().currentUser.getId();
但如果你绝对需要用户ID:
...
const name = event.data.data().name;
const email = event.data.data().email;
const userId = event.params.userID;
...
将为您提供新记录的身份。