From 64e9e20977c0f82ab3a02ac960306131f73a54e4 Mon Sep 17 00:00:00 2001 From: Marcel May Date: Thu, 1 Apr 2021 23:06:22 +0200 Subject: [PATCH] Example setup for GreenMail and nodemailer Test setup for reproducing #380 --- .../clients/nodemailer/Dockerfile | 14 ++++++++ greenmail-docker/clients/nodemailer/README.md | 12 +++++++ .../clients/nodemailer/docker-compose.yml | 16 +++++++++ greenmail-docker/clients/nodemailer/server.js | 34 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 greenmail-docker/clients/nodemailer/Dockerfile create mode 100644 greenmail-docker/clients/nodemailer/README.md create mode 100644 greenmail-docker/clients/nodemailer/docker-compose.yml create mode 100644 greenmail-docker/clients/nodemailer/server.js diff --git a/greenmail-docker/clients/nodemailer/Dockerfile b/greenmail-docker/clients/nodemailer/Dockerfile new file mode 100644 index 0000000000..c442ea7fd3 --- /dev/null +++ b/greenmail-docker/clients/nodemailer/Dockerfile @@ -0,0 +1,14 @@ +FROM node:lts-alpine + +ENV NODE_ENV=production \ + NPM_CONFIG_PRODUCTION=true + +WORKDIR /nodemailer +RUN addgroup nodemailer && \ + adduser -S nodemailer nodemailer && \ + chown -R nodemailer:nodemailer /nodemailer +USER nodemailer:nodemailer +COPY --chown=nodemailer server.js /nodemailer/server.js +RUN npm install --save nodemailer + +ENTRYPOINT [ "node","/nodemailer/server.js" ] diff --git a/greenmail-docker/clients/nodemailer/README.md b/greenmail-docker/clients/nodemailer/README.md new file mode 100644 index 0000000000..d43fc1e8f5 --- /dev/null +++ b/greenmail-docker/clients/nodemailer/README.md @@ -0,0 +1,12 @@ +GreenMail test setup with nodemailer +========= + +This is a POC showing a GreenMail and [nodemailer](https://github.com/nodemailer/nodemailer) setup, configuring nodemailer to send a single message to GreenMail. + +Run `docker-compose up --build` and use eg Thunderbird to verify + +|Port|Description| +|----|-----------| +|3025| GreenMail SMTP | +|3143| GreenMail IMAP | +|8080| GreenMail API | diff --git a/greenmail-docker/clients/nodemailer/docker-compose.yml b/greenmail-docker/clients/nodemailer/docker-compose.yml new file mode 100644 index 0000000000..4648ae1ef5 --- /dev/null +++ b/greenmail-docker/clients/nodemailer/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' +services: + greenmail: + image: greenmail/standalone:1.6.3 + environment: + # Enable GreenMail verbose mode + - GREENMAIL_OPTS=-Dgreenmail.setup.test.smtp -Dgreenmail.setup.test.imap -Dgreenmail.setup.api -Dgreenmail.hostname=0.0.0.0 -Dgreenmail.auth.disabled -Dgreenmail.verbose + ports: + - "3025:3025" + - "3143:3143" + - "8080:8080" + nodemailer: + build: + context: . + links: + - greenmail diff --git a/greenmail-docker/clients/nodemailer/server.js b/greenmail-docker/clients/nodemailer/server.js new file mode 100644 index 0000000000..67689fc524 --- /dev/null +++ b/greenmail-docker/clients/nodemailer/server.js @@ -0,0 +1,34 @@ +// From https://nodemailer.com/about/#example + +"use strict"; +const nodemailer = require("nodemailer"); + +// async..await is not allowed in global scope, must use a wrapper +async function main() { + // create reusable transporter object using the default SMTP transport + let transporter = nodemailer.createTransport({ + host: "greenmail", + port: 3025, + secure: false, + //auth: { + // user: 'foo', + // pass: 'bar', + //}, + debug: true, + logger: true, + }); + + // send mail with defined transport object + let info = await transporter.sendMail({ + from: '"Fred Foo 👻" ', // sender address + to: "foo2@bar.com, foo3@bar.com", // list of receivers + subject: "Hello ✔", // Subject line + text: "Hello world?", // plain text body + html: "Hello world?", // html body + }); + + console.log("Message sent: %s", info.messageId); +} + +main().catch(console.error); +