프로그래밍/NextJS

nextjs nodemailer 연동하기

타코코딩 2024. 1. 8. 14:24

# 이메일 보내기

 

- sendgrid 가입해야함

- twilioexplore products에서 email 누르면 sendgrid로 이동함

- 포기함 그냥 nodemailer 사용하는게 좋을듯

- - 네이버 이메일 > 환경설정 > pop3/imap tjfwjd

- - 탭두개다 사용함 체크하고 저장

- - npm install --save nodemailer @types/nodemailer

 

email.js 파일만들기
import nodemailer from "nodemailer";
const smtpTransport = nodemailer.createTransport({
service: "Naver", 
host: "smtp.naver.com", //앱에서확인가능
port: 587,  //앱에서확인가능
auth: {
user: process.env.MAIL_ID,  // 본인네이버메일
pass: process.env.MAIL_PASSWORD, // 본인비번(2단계인증에서 생성한 앱용 비번)
},
tls: {
rejectUnauthorized: false,
},
});



export default smtpTransport;

 

 

if (email) {
const mailOptions = {
from: process.env.MAIL_ID,
to: email,
subject: "Nomad Carrot Authentication Email",
text: `Authentication Code : ${payload}`,
};

const result = await smtpTransport.sendMail(
mailOptions,
(error, responses) => {
if (error) {
console.log(error);
return null;
} else {
console.log(responses);
return null;
}
}
);

smtpTransport.close();

console.log(result);

}

https://nodemailer.com/