-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67b520e
commit a675d6c
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Mailserver | ||
|
||
- [reference](https://i12bretro.github.io/tutorials/0779.html) | ||
|
||
# Prerequisite | ||
|
||
- Domain name and static IP (EC2) | ||
- Docker compose | ||
- [Host Port Forwarding](https://docker-mailserver.github.io/docker-mailserver/latest/config/security/understanding-the-ports/#overview-of-email-ports) | ||
|
||
# Quick Setup | ||
|
||
- Set `DOMAIN_NAME` to system env by command: | ||
|
||
```bash | ||
DOCKER_MAILSERVER_DOMAIN_NAME=ec2-111-111-111-11.ap.aws.com | ||
``` | ||
|
||
- Create main working directories | ||
|
||
```bash | ||
mkdir ~/docker/mailserver/{data,state,logs,config} -p | ||
``` | ||
|
||
- Run `docker-compose up -d` with `docker-compose.yml` | ||
|
||
```yaml | ||
docker run -d --name=mailserver --hostname="$HOSTNAME" --domainname="$DOCKER_MAILSERVER_DOMAIN_NAME" -p 25:25 -p 143:143 -p 587:587 -p 993:993 -e ENABLE_SPAMASSASSIN=1 -e SPAMASSASSIN_SPAM_TO_INBOX=1 -e ENABLE_CLAMAV=1 -e ENABLE_POSTGREY=1 -e ENABLE_FAIL2BAN=0 -e ENABLE_SASLAUTHD=0 -e ONE_DIR=1 -e TZ=America/New_York -v ~/docker/mailserver/data/:/var/mail/ -v ~/docker/mailserver/state/:/var/mail-state/ -v ~/docker/mailserver/logs/:/var/log/mail/ -v ~/docker/mailserver/config/:/tmp/docker-mailserver/ --restart=unless-stopped mailserver/docker-mailserver | ||
``` | ||
|
||
- Add admin user | ||
|
||
```bash | ||
docker run --rm -e MAIL_USER=admin@$DOCKER_MAILSERVER_DOMAIN_NAME -e MAIL_PASS=admin -it mailserver/docker-mailserver /bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p $MAIL_PASS)"' >> ~/docker/mailserver/config/postfix-accounts.cf | ||
``` | ||
|
||
> Check that the user has been added to the configuration file `~/docker/mailserver/config/postfix-accounts.cf` | ||
# Test | ||
|
||
```javascript | ||
const nodemailer = require("nodemailer"); | ||
|
||
let transporter = nodemailer.createTransport({ | ||
host: "ec2-122-248-230-39.ap-southeast-1.compute.amazonaws.com", | ||
port: 587, | ||
secure: false, // true for 465, false for other ports | ||
auth: { | ||
user: "admin@ec2-122-248-230-39.ap-southeast-1.compute.amazonaws.com", | ||
pass: "admin", | ||
}, | ||
tls: { rejectUnauthorized: false }, | ||
debug: true, | ||
logger: true, // Enable logger | ||
}); | ||
|
||
let mailOptions = { | ||
from: "admin@ec2-122-248-230-39.ap-southeast-1.compute.amazonaws.com", | ||
to: "admin@ec2-122-248-230-39.ap-southeast-1.compute.amazonaws.com", | ||
subject: "Hello ✔", | ||
text: "Hello world?", | ||
html: "<b>Hello world?</b>", | ||
}; | ||
|
||
transporter.verify((error) => { | ||
if (error) { | ||
return console.error("verify:", error); | ||
} | ||
|
||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
return console.error(error); | ||
} | ||
console.log("Message sent: %s", info.messageId); | ||
}); | ||
}); | ||
``` | ||
|
||
> Check that received mail is stored in `~/docker/mailserver/data/-/${user}/new` |