diff --git a/nodemailer/README.md b/nodemailer/README.md new file mode 100644 index 0000000..81448bd --- /dev/null +++ b/nodemailer/README.md @@ -0,0 +1,6 @@ +``` +docker compose up -d +# http://localhost:8025 にアクセスして確認 +pnpm i +node index.mjs +``` diff --git a/nodemailer/compose.yml b/nodemailer/compose.yml new file mode 100644 index 0000000..3761cfa --- /dev/null +++ b/nodemailer/compose.yml @@ -0,0 +1,19 @@ +services: + # maildev: + # image: maildev/maildev + # ports: + # - "1080:1080" # Web UI + # - "1025:1025" + # environment: + # MAILDEV_INCOMING_USER: postmaster + # MAILDEV_INCOMING_PASS: password + mailpit: + image: axllent/mailpit + ports: + - "8025:8025" # Web UI + - "1025:1025" + environment: + MP_SMTP_AUTH_FILE: /etc/mailpit/auth + MP_SMTP_AUTH_ALLOW_INSECURE: "true" + volumes: + - ./etc/mailpit:/etc/mailpit:ro diff --git a/nodemailer/etc/mailpit/auth b/nodemailer/etc/mailpit/auth new file mode 100644 index 0000000..7eaaa96 --- /dev/null +++ b/nodemailer/etc/mailpit/auth @@ -0,0 +1 @@ +postmaster:password diff --git a/nodemailer/index.mjs b/nodemailer/index.mjs new file mode 100644 index 0000000..8ff11e1 --- /dev/null +++ b/nodemailer/index.mjs @@ -0,0 +1,20 @@ +import nodemailer from "nodemailer"; + +const transporter = nodemailer.createTransport({ + host: "localhost", + port: 1025, + secure: false, + auth: { + user: "postmaster", + pass: "password", + }, +}); + +const info = await transporter.sendMail({ + from: "foo ", + to: "bar ", + subject: "Hello world!", + html: "Hello world.", +}); + +console.log(info.messageId); diff --git a/nodemailer/package.json b/nodemailer/package.json new file mode 100644 index 0000000..f868a31 --- /dev/null +++ b/nodemailer/package.json @@ -0,0 +1,15 @@ +{ + "name": "nodemailer", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Kohei Watanabe ", + "license": "MIT", + "devDependencies": { + "nodemailer": "^6.9.4" + } +} diff --git a/nodemailer/pnpm-lock.yaml b/nodemailer/pnpm-lock.yaml new file mode 100644 index 0000000..e1605b0 --- /dev/null +++ b/nodemailer/pnpm-lock.yaml @@ -0,0 +1,13 @@ +lockfileVersion: '6.0' + +devDependencies: + nodemailer: + specifier: ^6.9.4 + version: 6.9.4 + +packages: + + /nodemailer@6.9.4: + resolution: {integrity: sha512-CXjQvrQZV4+6X5wP6ZIgdehJamI63MFoYFGGPtHudWym9qaEHDNdPzaj5bfMCvxG1vhAileSWW90q7nL0N36mA==} + engines: {node: '>=6.0.0'} + dev: true