Skip to content

Latest commit

ย 

History

History
58 lines (46 loc) ยท 1.64 KB

node-js06.md

File metadata and controls

58 lines (46 loc) ยท 1.64 KB

Node.js - ์ด๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๊ธฐ (nodemailer)

nodemailer ๋ชจ๋“ˆ

  • ์‹œ์Šคํ…œ์—์„œ ์ด๋ฉ”์ผ์„ ๋ณด๋‚ด๋Š” ๊ธฐ๋Šฅ
  • ์„œ๋น„์Šค ์šด์˜ ์œ„ํ•ด ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ
  • ์ด๋ฉ”์ผ ๋ฐœ์†ก ๊ฐ€๋Šฅํ•œ ๋ฉ”์ผ ์„œ๋ฒ„ ํ•„์š”
    => Mailtrap.io ์ด์šฉ! (๋ฌด๋ฃŒ ๊ฐœ๋ฐœ ํ…Œ์ŠคํŠธ ์šฉ๋„๋กœ ํ™œ์šฉ ๊ฐ€๋Šฅ)
const nodemailer = require('nodemailer');

const email = {
  host: 'smtp.mailtrap.io',
  port: 2525,
  secure: false,
  auth: {
    user: '1c6525bec23ec2',
    pass: 'a08f059bf556a2',
  },
};

const send = async (data) => {
  nodemailer.createTransport(email).sendMail(data, (err, info) => {
    if (error) console.log(error);
    else {
      console.log(info);
      return info.response;
    }
  });
};

const content = {
  from: 'pangoons@gmail.com',
  to: '339802414c-296c7d@inbox.mailtrap.io',
  subject: '๊ฐœ๋ฐœ์ž์˜ ํ’ˆ๊ฒฉ',
  // text: '๊ฐœ๋ฐœ์ž์˜ ํ’ˆ๊ฒฉ - nodemailer๋ฅผ ์ด์šฉํ•œ ์ด๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ ๊ตฌํ˜„',
  html: '<h2>๊ฐœ๋ฐœ์ž์˜ ํ’ˆ๊ฒฉ - nodemailer๋ฅผ ์ด์šฉํ•œ ์ด๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ ๊ตฌํ˜„</h2>',
};

send(content);

[Note]

  • ํ™œ์šฉ
    • ํŠน์ • ์›น์‚ฌ์ดํŠธ ํšŒ์›๊ฐ€์ž… ํ•˜๊ณ  ๋‚˜๋ฉด, ํ™•์ธ ์ธ์ฆ ๋ฉ”์ผ ๋ฐœ์†ก
    • ๊ธฐ์—…์šฉ ์—…๋ฌด ์‹œ์Šคํ…œ; ๋งค๋‹ˆ์ €๊ฐ€ ์—…๋ฌด ๋“ฑ๋กํ•˜๋ฉด์„œ ํŠน์ • ๋‹ด๋‹น์ž ์ง€์ •ํ•˜๋ฉด
      ๊ทธ ์—…๋ฌด ๋“ฑ๋ก๋˜๋Š” ์ˆœ๊ฐ„์— ๋‹ด๋‹น์ž์—๊ฒŒ ์—…๋ฌด ์ง€์‹œ ๋ฉ”์ผ ๋ฐœ์†ก๋จ
    • ๋งค์›”, ๋งค์ฃผ, ํŒ๋งค ์‹ค์ ์„ ์ž„์› ํ˜น์€ ๋งค๋‹ˆ์ €์—๊ฒŒ ์ง‘๊ณ„ํ•ด์„œ ๋ฐœ์†ก๋˜๋Š” ์ด๋ฉ”์ผ
    • ๋‰ด์Šค๋ ˆํ„ฐ; ํ•ด๋‹น ์›น์‚ฌ์ดํŠธ๋กœ๋ถ€ํ„ฐ ์ •๊ธฐ์ ์œผ๋กœ ์ด๋ฉ”์ผ์ด ๋ฐœ์†ก๋จ
    • ์Šค์ผ€์ค„๋Ÿฌ์™€ ํ•จ๊ป˜ ํ™œ์šฉ (์ฒจ๋ถ€ํŒŒ์ผ๋„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Œ)

Reference