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 如何在NestJSAPI中为电子邮件模板提供静态文件_Node.js_Angular_Express_Nestjs_Email - Fatal编程技术网

Node.js 如何在NestJSAPI中为电子邮件模板提供静态文件

Node.js 如何在NestJSAPI中为电子邮件模板提供静态文件,node.js,angular,express,nestjs,email,Node.js,Angular,Express,Nestjs,Email,我想在公用文件夹中有一个电子邮件模板。我不知道如何在发送电子邮件功能中导入/使用电子邮件模板。我得到了这个错误 找不到模块“../../public/view/email模板”。t 我已经为nest添加了这一行,以便使用public folder来提供包含HTML、CSS和js文件的静态文件 app.useStaticAssets(join(__dirname, '..', 'public')); 这是发送电子邮件模板功能 import nodemailer = require('node

我想在公用文件夹中有一个电子邮件模板。我不知道如何在发送电子邮件功能中导入/使用电子邮件模板。我得到了这个错误

找不到模块“../../public/view/email模板”。t

我已经为nest添加了这一行,以便使用public folder来提供包含HTML、CSS和js文件的静态文件

  app.useStaticAssets(join(__dirname, '..', 'public'));
这是发送电子邮件模板功能

import nodemailer = require('nodemailer');
import sgTransport = require('nodemailer-sendgrid-transport');
import {emailTem} from '../../public/view/email-template'; //This is where I am importing the HTML template

export const SendEmail = async (email: string, link: string, name: string) => {

    const options = {
        auth: {
            api_user: process.env.SG_UserName,
            api_key: process.env.SG_Password
        }
    }


    const client = nodemailer.createTransport(sgTransport(options));

    const emailObj = {
        from: 'noreply@mail.com',
        to: email,
        subject: "Email Confirmation from Us",
        text: emailTem,
        html: emailTem
    };

    client.sendMail(emailObj, function (err, info) {
        if (err) {
            console.log(err);
        }
        else {
            console.log('Message sent: ' + link);
        }
    });

}
 }

在email-template.js中,编写一个函数,将html导出为字符串,然后使用它

export function emailTem() {
let html =`<html></html>`;
return html;
}
import {emailTem} from '../../public/view/email-template';