nodemailer - RLidea/dev.docs GitHub Wiki

nodejs๊ฐ€ php๋ณด๋‹ค ๋ฉ”์ผ๋ณด๋‚ด๊ธฐ ์ข‹๋‹ค๋‹ˆ ๊นœ์ง๋†€๋ž๋‹ค. nodemailer๋ฅผ ์ด์šฉํ–ˆ๋‹ค.

Gmail๋กœ ์„ค์ •ํ•˜๊ธฐ

  1. https://myaccount.google.com/lesssecureapps ์—์„œ '๋ณด์•ˆ ์ˆ˜์ค€์ด ๋‚ฎ์€ ์•ฑ ํ—ˆ์šฉ'์„ ํ•ด์ค˜์•ผ ํ•œ๋‹ค. (๋กœ์ปฌ์—์„œ๋งŒ ํ…Œ์ŠคํŠธํ•  ๋•Œ๋Š” ์ด๊ฒƒ๋งŒ์œผ๋กœ ์ถฉ๋ถ„)
  2. https://accounts.google.com/DisplayUnlockCaptcha ์—์„œ๋„ '๊ณ„์†'์„ ๋ˆŒ๋Ÿฌ ๋‹ค๋ฅธ ์•ฑ์—์„œ ๋กœ๊ทธ์ธ์„ ํ—ˆ์šฉํ•ด์ค˜์•ผํ•œ๋‹ค. (AWS ๋“ฑ์—์„œ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ด ๊ณผ์ •๋„ ํ•„์š”ํ•จ)

nodemailer

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

npm i nodemailer

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ:

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '[email protected]',
    pass: 'your_password',
  },
});

const mailOption = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'ํ…Œ์ŠคํŠธ',
  text: '์ž…๋‹ˆ๋‹ค.',
};

transporter.sendMail(mailOption, (err, info) => {
  if (err) console.error(err);
  console.log(info);
});