我正在尝试使用 fs.readFile('../emailTemplates/template.html') 从 index.ts 读取 html 文件
我的文件夹:
--src
--index.ts
--UsersFunctions
--UserFunctions.ts
--emailTemplates
--template.html
来自 index.ts :
import * as UsersFunctions from './UsersFunctions/UsersFunctions';
export const newUserRegister = UsersFunctions.onCreateNewUser;
来自 UsersFunctions.ts
export const onCreateNewUser = functions.firestore.document('users/allUsers/usersData/{userId}').onCreate(async (snap, context) => {
fs.readFile("../emailTemplates/template.html", {encoding: 'utf-8'}, (err, html) => {
if (err) {
console.log(err);
}
else {
}
});
}
我从 firebase 函数中收到错误:
Error: ENOENT: no such file or directory, open '../emailTemplates/template.html'
at Error (native)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: 'user_code/lib/emailTemplates/newUserRegisterHtmlTemplate.html'
我只想发送一封带有 html 模板的电子邮件 也许还有另一种方法可以做到吗? 我厌倦了搜索,但没有找到任何关于带有 typescript 的 frirebase 函数的电子邮件模板
最佳答案
问题是您的模板路径与您的项目文件组织不匹配。我建议您只将 TypeScript 源代码放在 src
中,而将所有其他您要读写的文件放在与 src< 同一级别的
。所以,你可以这样组织你的文件:functions
文件夹下
/functions
/src
/index.ts
/other source files
/emailTemplates
/template.html
然后,在 index.ts 中,您可以使用相同的路径 ../emailTemplates/template.html
读取 template.html。
关于typescript - Firebase Functions Typescript - 使用 html 模板发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50999550/