我正在尝试通过Firebase的Cloud Functions发送电子邮件,但是无论何时激活该功能,都会出现此错误。 该功能应该在信息存储到集合中后立即激活,我正在寻找集合所具有的相同数据,以便在检查集合是否正确存储时可以发送电子邮件。 我尝试以不同的方式编写代码,但总是会发生相同的事情。有人知道会发生什么吗?帮助:(
第一个代码:
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
let transport = nodemailer.createTransport({
service: "smtp.gmail.com",
auth: {
user: 'user@gmail.com',
pass: 'xyz'
}
})
exports.mail = functions.firestore.document('alreadymademail/{docId}').onCreate((snap, context) => {
const email = snap.data().email
const title = snap.data().title
const message = snap.data().message
console.log(snap.data());
return sendMail(email, title, message)
});
function sendMail(email, title, message){
return transport.sendMail({
from: 'hihi@gmail.com',
to: email,
subject: title,
text: message
})
.then(r => console.log(r))
.catch(e => console.log(e));
}
第二个代码:
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const admin = require('firebase-admin');
admin.initializeApp()
require('dotenv').config()
const {SENDER_EMAIL,SENDER_PASSWORD} = process.env;
exports.sendEmailNotification = functions.firestore.document('alreadymademail/{docId}').onCreate((snap,ctx)=>{
const data = snap.data();
let autData=nodemailer.createTransport({
host: 'gmail',
port: 465,
secure: true,
auth:{
user: user@gmail.com,
pass: xyz
}
});
autData.sendMail({
from :'hihi@gmail.com',
to: `${data.email}`,
subject: `${data.title}`,
text: `${data.message}`,
html: `${data.message}`
}).then(res=>console.log('Se mando')).catch(err=>console.log(err));
});
第三个代码
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
exports.mail = functions.firestore.document('alreadymademail/{docId}').onCreate((snap, context) => {
const email = snap.data().email
const title = snap.data().title
const message = snap.data().message
console.log(snap.data());
});
let transport = nodemailer.createTransport({
service: "smtp.gmail.com",
auth: {
user: 'user@gmail.com',
pass: 'xyz'
}
})
transport.sendMail({
from: 'hihi@gmail.com',
to: email,
subject: title,
text: message
})
.then(r => console.log(r))
.catch(e => console.log(e));
}