Sandbox subdomains are for test purposes only. Please add your own domain or add the address to recipients in Account Settings

broccoli·2021년 5월 17일
0

tools

목록 보기
5/5
post-thumbnail

저 에러는 메세지에 적힌대로 custom domain을 사용하거나 email을 보낼 주소를 recipient로 등록하거나 해야 발생하지 않는 에러이다.

1. recipient로 등록하기

1-1. recipient등록

mailgun 로그인 > Sending > Domains > Domain 선택 > 을 하면 아래 이미지로 이동된다. 이때 아래 인풋박스에 해당 이메일을 저장한다.
authorized recipients

1-2. recipient verified 하기

등록을 마치면 이메일은 unverified 상태가 된다. 이상태를 verified하려면 해당 이메일에가서 확인링크를 클릭 해줘야한다.

2. mailgun with nodemailer-mailgun-transport 사용예시

// mailService.js
const nodemailer = require('nodemailer')
const mg = require('nodemailer-mailgun-transport')
const Logger = require('./logger')

const sendMail = (email) => {
  const options = {
    auth: {
      api_key: process.env.MAILGUN_KEY,
      domain: process.env.MAILGUN_DOMAIN
    }
  }
  const client = nodemailer.createTransport(mg(options))
  return client
    .sendMail(email)
    .then(() => {
      Logger.debug('✅ Message Sent!!')
    })
    .catch((error) => Logger.error(error))
}

const sendSecretMail = (address, secret) => {
  const email = {
    from: 'noreply@broccolidb.com',
    to: address,
    subject: 'Login with this Link',
    html: `<main>
    <h1>비밀번호변경</h1>
    broccoli의 비밀번호변경을 위해서는 아래 버튼을 통해 비밀번호 변경을 해주세요.
    <a href=http://localhost:3065/auth?token=${secret}><button>비밀번호변경</button></a>
    </main>`
  }
  return sendMail(email)
}

module.exports = {
  sendSecretMail
}
profile
🌃브로콜리한 개발자🌟

0개의 댓글