Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Created November 28, 2022 04:15
Show Gist options
  • Save yano3nora/dbbef9cfbb7f3a48a16280e30f631a77 to your computer and use it in GitHub Desktop.
Save yano3nora/dbbef9cfbb7f3a48a16280e30f631a77 to your computer and use it in GitHub Desktop.
[js: nodemailer] Send e-mails with Node.JS – easy as cake! #js

Overview

Nodemailer
github.com/nodemailer/nodemailer

Getting Started

Nodemailerの使い方

$ npm i nodemailer
$ npm i -D @types/nodemailer
import { createTransport } from 'nodemailer'

const transporter = createTransport({
  host: 'mail.example.com',
  port: 465,
  secure: true,
  auth: {
    user: process.env.SMTP_USERNAME,
    pass: process.env.SMTP_PASSWORD,
  }
})

try {
  await transporter.sendMail({
    from: '[email protected]',
    to: '[email protected]',
    subject: '...',
    text: '...',
  })
} catch (e) {
  console.log('メール送信失敗')
  throw e
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment