Skip to content

Commit

Permalink
Example setup for GreenMail and nodemailer
Browse files Browse the repository at this point in the history
Test setup for reproducing #380
  • Loading branch information
marcelmay committed Apr 1, 2021
1 parent a5d7301 commit 64e9e20
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
14 changes: 14 additions & 0 deletions greenmail-docker/clients/nodemailer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
12 changes: 12 additions & 0 deletions greenmail-docker/clients/nodemailer/README.md
Original file line number Diff line number Diff line change
@@ -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 |
16 changes: 16 additions & 0 deletions greenmail-docker/clients/nodemailer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions greenmail-docker/clients/nodemailer/server.js
Original file line number Diff line number Diff line change
@@ -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 👻" <[email protected]>', // sender address
to: "[email protected], [email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});

console.log("Message sent: %s", info.messageId);
}

main().catch(console.error);

0 comments on commit 64e9e20

Please sign in to comment.