NodeJS를 처음 사용했습니다. 나는 contact us 페이지에서 일하기 시작했습니다.이 페이지는 제출 될 때 다음 HTML이 포함 된 확인 이메일을 사용자에게 발송합니다.NodeJS의 다른 파일에서 HTML (전자 메일 본문)을 읽는 방법
<p>Hello Sujit,</p>
<p>Thank you for approaching us.</p>
<p>We have received your request and our executive will get in touch with you soon.</p>
<p>Thank you.</p>
다음은 이메일 보낼 수있는 코드 :
var mailer = require("nodemailer");
var emailBody = "<HTML above>";
// Use Smtp Protocol to send Email
var smtpTransport = mailer.createTransport("SMTP",{
service: "#######",
auth: {
user: "#########",
pass: "#######"
}
});
var mail = {
from: "######################",
to: params.email,
subject: "Welcome user.",
text: "",
html: emailBody
}
smtpTransport.sendMail(mail, function(error, response){
if(error){
console.log("Mail error:>>");
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
smtpTransport.close();
});
는 현재 nodemailer를 사용하여, 나는 동일한 파일에 정의 된 HTML의 몸이 이메일을 보내고 - app.js. 지금까지 잘 작동합니다. 그러나 본문 내용을 직접 관리 할 수 있도록 HTML의 변수/자리 표시자를 "이름"과 다른 파일에 배치 할 수있는 방법이 있습니까? 본문 내용을 변수 emailBody
에로드 할 수있는 방법.
감사합니다.
노드는 템플릿에 사용할 수 많은 모듈이 있습니다. – Quentin
https://nodemailer.com/2-0-0-beta/templating/ – Rayon