我正在尝试通过电子邮件将自己的Firebase数据库发送给OnCreate。在google cloud函数中测试此错误时,我收到错误消息“忽略已完成函数的异常”。
pd.to_datetime(df.Date,dayfirst=True).dt.strftime('%m%d%Y').to_excel('your.xls')
Out[722]:
463 05142019
535 05032019
570 05112019
577 05092019
628 08082019
630 05252019
Name: Date, dtype: object
我希望收到一封电子邮件,但我却收到了来自Google Cloud tester的错误,该错误指出“忽略已完成功能的异常”,尽管控制台也返回了“成功!”。这是完整的错误:
const functions = require('firebase-functions'); const nodemailer = require('nodemailer'); const gmailEmail = functions.config().gmail.email; const gmailPassword = functions.config().gmail.password; const mailTransport = nodemailer.createTransport({ service: 'gmail', auth: { user: gmailEmail, pass: gmailPassword, }, }); const APP_NAME = 'Your App'; exports.sendWelcomeEmail = functions.database.ref('/PickupRequests{pushID}').onCreate((snapshot, context) => { return sendWelcomeEmail(); }); async function sendWelcomeEmail() { const mailOptions = { from: "<noreply@firebase.com>", to: "info@abc.com", subject: "New Request" }; await mailTransport.sendMail(mailOptions); return console.log("Success!"); }
答案 0 :(得分:0)
我可以通过以下代码解决此问题:
'use strict';
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const username = functions.config().gmail.email;
const password = functions.config().gmail.password;
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: gmailEmail,
pass: gmailPassword,
},
});
exports.sendPickupRequest = functions.database.ref('/PickupRequests/{pushId}').onCreate(async(snapshot, context) => {
const val = snapshot.val();
const final = JSON.stringify(val)
const mailOptions = {
from: gmailEmail,
to: "info@abc.com",
subject: "New Request"
};
try {
await mailTransport.sendMail(mailOptions);
console.log('email sent');
} catch(error) {
console.error('There was an error while sending the email:', error);
}
return null;
});