GithubHelp home page GithubHelp logo

mailbee's Introduction

๐Ÿ Mailbee: Forms Backend

๐Ÿ 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.

Why do I copy MailBear ?

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.

Run with Docker

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.

Run in Development

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

Build image

docker build -t mailbee ./docker/Dockerfile-node

Forms configuration

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]

Usage

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."}'

Usage with HTML form element

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>

Environment variable summary

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

Mail template

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 Email entered bu user
name Name entered by user
content Message entered by user
content Time and date of mail submission

Metrics

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.

Acknowledgements

mailbee's People

Contributors

ctrlouis avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.