在我的Android应用中,当用户多次输入错误的PASSWORD时,我想使用Firebase函数向用户发送电子邮件,并捕获图片的下载链接,因此我在下面创建了函数。 因此,我将电子邮件和下载链接推送到firebase,并在添加数据时触发了以下功能,但是每当我尝试部署该功能时,cli都会给我错误,表明邮件传输是意外的。
exports.sendMails = functions.database.ref('/failedAttemps/{email2}/{attemptsid}')
.onWrite((data, context) =>
{
const email2 = context.params.email2;
const attemptsid = context.params.attemptsid;
//const sender_id = context.params.sender_id;
//const mees = context.params.message_not;
// contentss = mees;
const gmailEmail = functions.config().gmail.email;
const gmailPassword = functions.config().gmail.password;
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: "******@gmail.com",
pass: "****@****",
},
});
const email = admin.database().ref(`/Notification/${email2}/${attemptsid}/email`);
email.once("value", function(snapshot){
emails = snapshot.val();
});
const naam = admin.database().ref(`/Notification/${email2}/${attemptsid}/dlink`);
naam.once("value", function(snapshot){
dlinks = snapshot.val();
});
// console.log('message :' , contentss);
const mailOptions = {
from: '"LetsTalk" <noreply@firebase.com>',
to: emails,
};
// Building Email message.
mailOptions.subject = 'Someone tried to login to you account';
mailOptions.text = `${dlink}Thanks you for subscribing to our newsletter. You will receive our next weekly newsletter.`;
try {
await mailTransport.sendMail(mailOptions);
// console.log(`New ${subscribed ? '' : 'un'}subscription confirmation email sent to:`, val.email);
} catch(error) {
console.error('There was an error while sending the email:', error);
}
return null;
});
每次我尝试在Firebase上部署功能时,都会弹出此错误enter image description here
答案 0 :(得分:0)
问题似乎是您在使用await
时没有首先表明它是async
函数。
尝试将您的第一行替换为:
exports.sendMails = functions.database.ref('/failedAttemps/{email2}/{attemptsid}')
.onWrite(async (data, context) =>
{