Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在firebase云功能中为NodeEmailer创建自定义电子邮件模板?_Node.js_Google Cloud Functions_Handlebars.js_Nodemailer - Fatal编程技术网

Node.js 在firebase云功能中为NodeEmailer创建自定义电子邮件模板?

Node.js 在firebase云功能中为NodeEmailer创建自定义电子邮件模板?,node.js,google-cloud-functions,handlebars.js,nodemailer,Node.js,Google Cloud Functions,Handlebars.js,Nodemailer,任何人都可以参与到如何创建一个动态电子邮件模板来与firebase云功能一起使用吗? 基本上,我创建了一个函数,在点击/sendmail端点时将调用该函数。它将数据保存在req正文中,我正在检索该数据并使用NodeEmailer通过电子邮件发送它 如果我想使用把手创建模板,则会出现路径错误。错误是不存在这样的文件或目录。我尝试了两个不同的路径,第一个在functions/src/email/template.html下,第二个与functions文件夹处于同一级别 发送邮件功能 const tr

任何人都可以参与到如何创建一个动态电子邮件模板来与firebase云功能一起使用吗? 基本上,我创建了一个函数,在点击
/sendmail
端点时将调用该函数。它将数据保存在
req
正文中,我正在检索该数据并使用NodeEmailer通过电子邮件发送它

如果我想使用
把手
创建模板,则会出现路径错误。错误是
不存在这样的文件或目录
。我尝试了两个不同的路径,第一个在
functions/src/email/template.html
下,第二个与functions文件夹处于同一级别

发送邮件功能
const transporter=nodeEmailer.createTransport({
服务:“gmail”,
认证:{
用户:'example@gmail.com',
通过:“dqsdsqdqsdsq”
}
});
const filePath=path.join(uu dirname,'functions/src/Email/template.html');
const source=fs.readFileSync(文件路径'utf-8').toString();
const template=handlebar.compile(源代码);
常量替换={
学名:学名,
className:className,
日期:新日期(),
负责人:负责人,
纪念的:纪念的
};
const htmlToSend=模板(替换);
常量邮件选项={
from:'ADMIN',//类似于:Jane Doe
目的地:,
主题:`类${className}|${schoolName}|${new Date()}的会话代码,//电子邮件主题
html:htmlToSend
};
return transporter.sendMail(邮件选项,(错误,信息)=>{
如果(错误){
返回句柄错误(res,error);
}
返回res.status(200).json({
时间戳:新日期(),
现状:200,
消息:`电子邮件已成功发送到${destination}`,
额外:“”
});
});

替换这行代码

const filePath = path.join(__dirname, 'functions/src/Email/template.html');


替换这行代码

const filePath = path.join(__dirname, 'functions/src/Email/template.html');


部署功能时,functions文件夹中的所有内容都将打包并发送到云功能。不会发送该文件夹之外的任何内容,这意味着您的template.html文件夹在运行时不可用。如果您希望所部署的代码在运行时能够读取内容,则在运行deploy命令之前,它应该位于functions文件夹中。

当您部署函数时,functions文件夹中的所有内容都会打包并发送到云函数。不会发送该文件夹之外的任何内容,这意味着您的template.html文件夹在运行时不可用。如果希望部署的代码在运行时能够读取内容,则在运行部署命令之前,它应该位于functions文件夹中。

什么是console.log(\uu dirname)打印出来?path.join()将使用函数/src/Email/template.html连接\uuuu目录名。/您能再次确认\uuu目录名和连接的路径吗?我试图做的事情似乎有些牵强,因此,在normal.ts中之前,我必须在nodeEmailer中创建一个html节,然后将其分配给html选项:/n您确认路径了吗?替换以下行const filePath=path.join(u dirname,'functions/src/Email/template.html');使用const filePath=path.join(“”,'src/Email/template.html');控制台日志(\uuuu dirname)打印出来的是什么?path.join()将使用函数/src/Email/template.html连接\uuuu目录名。/您能再次确认\uuu目录名和连接的路径吗?我试图做的事情似乎有些牵强,因此,在normal.ts中之前,我必须在nodeEmailer中创建一个html节,然后将其分配给html选项:/n您确认路径了吗?替换以下行const filePath=path.join(u dirname,'functions/src/Email/template.html');使用const filePath=path.join(“”,'src/Email/template.html');
const filePath = path.join('', 'src/Email/template.html');