🐝 MailBee is a JS version of 🐻 MailBear (by version, I mean copy)
MailBee is an open source, self hosted forms backend. Just do a post request to the API with some form data, and MailBee will make sure the submission is sent to you via mail!
MailBee will always hide the email address of the recepient, since the forms are accessed by a unique key.
I liked the way MailBear was build and the features available. But some was missing and I don't really know Go language so I don't forked original repo.
You can easily run MailBee with Docker:
Copy config_sample.yml
to config.yml
, template_sample.html
to template.html
and run the server:
docker network create mailbee_network # create network to link api with db
docker run --name redis_mailbee --network mailbee_network -d redis:7 # redis is required for rate limiting
docker run \
-p 3000:3000 \
-v ${PWD}/config.yml:/mailbee/config.yml \
-v ${PWD}/template.html:/mailbee/template.html \
--name mailbee \
--network mailbee_network \
-d ctrlouis/mailbee # start mailbee
For your convenience I created a docker-compose.yml file.
Copy config_sample.yml
to config.yml
, template_sample.html
to template.html
and run the server:
docker-compose -f docker-compose.dev.yml up
Api is available at :3000
, Prometheus at :8080
docker build -t mailbee ./docker/Dockerfile-node
Configuration is very simple. Just create as many forms as you want in config.yml
:
global:
smtp:
host: smtp.example.com
port: 25
user:
password:
disable_tls: true
from_email: [email protected]
from_name: MailBee
forms:
some-form-name:
name: some-form-name
key: some-random-key
overwrite_subject: true
allowed_domains:
- localhost:8080
- example.com
to_email:
- [email protected]
Once MailBee is running you can send requests with form data in the JSON body:
curl \
-X POST \
http://localhost:3000/api/v1/form/some-random-key \
-H 'Content-Type: application/json' \
-H 'Origin: http://localhost:8080' \
-d '{"name":"Mathias Beke","email":"[email protected]", "subject": "Some subject", "content": "Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis."}'
Query params redirect
and redirect_error
are available to your convenient :
?redirect
// redirect in case of success and error if param redirect_error is not provide?redirect_error
// redirect in case of error
<form action="http://localhost:3000/api/v1/form/some-form-key?redirect=http://domaine.com/form-page.html&redirect_error=http://domaine.com/form-page.html?error" method="post">
<input type="email" name="email" value="" required>
<input type="text" name="name" value="" required>
<input type="hidden" name="subject" value="" required>
<input type="text" name="content" placeholder="Message" value="Salut les potes !" required>
<button type="submit">Envoyer</button>
</form>
Variable | Default value | Description |
---|---|---|
PORT | 3000 | Api listening port |
METRICS_PORT | 3001 | Metrics listening port |
CONFIGPATH | /mailbee/config.yml | Path to config.yml file |
TEMPLATEPATH | /mailbee/template.html | Path to template.html file |
DEFAULT_SUBJECT | *New message ✉️ * | Default mail subject |
RATE_LIMITER_MAX | 5 | The maximum number of requests within RATE_LIMITER_DURATION |
RATE_LIMITER_DURATION | 120 | How long keep records of requests in seconds |
Build the mail template you want with template.html
file. HTML is generate with EJS. Variable syntax is <%= variable %>. Following variables are available to use is your template :
Variable | Description |
---|---|
formName | Form name |
Email entered bu user | |
name | Name entered by user |
content | Message entered by user |
content | Time and date of mail submission |
Prometheus metrics can be found on :3001/metrics
by default. To get statistics of submissions per form use this metric: mailbee_form_submissions_total{form="some-form-name"}
.
A Grafana dashboard for these metrics is available here: ./dashboard.json
Grafana dashboard can be found on :9090
by default.