我正在使用Cloud Functions for Firebase和Nodemailer,并将代码组合在一起以发送欢迎电子邮件。以下是我的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const nodemailer = require('nodemailer');
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);
const mailTransport = nodemailer.createTransport(
`smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`);
const APP_NAME = 'Test';
exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
const user = event.data; // The Firebase user.
const email = user.email; // The email of the user.
const displayName = user.displayName; // The display name of the user.
return sendWelcomeEmail(email, displayName);
});
function sendWelcomeEmail(email, displayName) {
const mailOptions = {
from: '"Test" <noreply@test.com>',
to: email
};
// The user subscribed to the newsletter.
mailOptions.subject = `Welcome to hell!`;
mailOptions.text = `Hey I hope you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
console.log('New welcome email sent to:', email);
});
}
firebase functions:config:get
答案 0 :(得分:1)
我只是使用您在配置中添加的from:
中的正确电子邮件地址解决了这个问题。
from: '"Test" <youremail@gmail.com>',