-
Notifications
You must be signed in to change notification settings - Fork 0
nodemailer
Centell edited this page Apr 23, 2020
·
3 revisions
nodejs가 php보다 메일보내기 좋다니 깜짝놀랐다. nodemailer를 이용했다.
- https://myaccount.google.com/lesssecureapps 에서 '보안 수준이 낮은 앱 허용'을 해줘야 한다. (로컬에서만 테스트할 때는 이것만으로 충분)
- https://accounts.google.com/DisplayUnlockCaptcha 에서도 '계속'을 눌러 다른 앱에서 로그인을 허용해줘야한다. (AWS 등에서 사용할 때는 이 과정도 필요함)
라이브러리 설치
npm i nodemailer
테스트 코드:
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'your_id@gmail.com',
pass: 'your_password',
},
});
const mailOption = {
from: 'your_id@gmail.com',
to: 'to@email.com',
subject: '테스트',
text: '입니다.',
};
transporter.sendMail(mailOption, (err, info) => {
if (err) console.error(err);
console.log(info);
});