【发布时间】:2019-10-17 10:50:57
【问题描述】:
我有一个 firebase 数据库,其中 onCreate Google Cloud Functions 调用 nodemailer 并向我发送电子邮件。一切正常,但现在我正在尝试在电子邮件中包含添加到数据库中的数据。我无法让它工作,似乎是因为它不是文本格式,我已经尝试转换为文本,但似乎没有这样做。我做错了什么?
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
// Configure the email transport using the default SMTP transport and a GMail account.
// For other types of transports such as Sendgrid see https://nodemailer.com/transports/
// TODO: Configure the `gmail.email` and `gmail.password` Google Cloud environment variables.
const gmailEmail = functions.config().gmail.email;
const gmailPassword = functions.config().gmail.password;
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: gmailEmail,
pass: gmailPassword,
},
});
exports.sendWelcomeEmail = functions.database.ref('/PickupRequests/{pushId}')
.onCreate(async(snapshot, context) => {
const val = snapshot.data;
const mailOptions = {
from: '<noreply@firebase.com>',
to: "mike@puravidalaundry.com",
subject: "New Pickup Request",
text: val //How do i convert this to a text format?
};
try {
await mailTransport.sendMail(mailOptions);
console.log('email sent');
} catch(error) {
console.error('There was an error while sending the email:', error);
}
return null;
});
【问题讨论】:
标签: node.js firebase-realtime-database google-cloud-functions nodemailer