当我在Firebase数据库中创建新订单时,我想发送电子邮件,但是创建订单时没有任何反应。我的功能:
exports.sendEmailConfirmation = functions.database.ref('/orders').onCreate(event => {
const mailOptions = {
from: '"Someone." <noreply@firebase.com>',
to: 'someone@gmail.com',
};
// Building Email message.
mailOptions.subject = 'New order from mobile app!';
mailOptions.text = 'John Doe lorem ipsum';
return mailTransport.sendMail(mailOptions)
.then(() => console.log('¡¡¡ Enail sent !!!'))
.catch((error) => console.error('Error!!', error));
});
Run Code Online (Sandbox Code Playgroud)
此代码使用onWrite()工作。