/mailer

Email sending API built on fiber

Primary LanguageGo

Mailer

An Email sending API built on fiber.

Endpoints

POST /send

The main endpoint of this API used to send emails, the body of the email is application/json.

Body:

{
    "target": "Name <Email_address>",
    "subject": "Email subject",
    "body": "Email content in text/html"
}

Env

The environment variables are quite extensive in this API and you will need all of them for the API to work properly.

EMAIL_PASSWORD=email_password
EMAIL_NAME=notifications
EMAIL_ADDRESS=noreply@example.com
SMTP_PORT=smtp.example.com
SMTP_URI=465
PORT=3600

Config

The API requires an keys.toml file next to the root of the project.
This file concists of the api keys and service names of the keys to give yourself or others access to the API.
To add a key simply add:

[[keys]]
token="random_character_string_you_generate_yourself"
service="service_name_so_you_can_identify_the_token"

To the keys.toml file

Headers

The API only allows a Content-Type of application/json.
All the requests need to be authorized with a self-generated token as shown above send via the Authorization header.
The Authorization header has to have the Bearer keyword so the end result needs to look similar to this:

Authorization: Bearer random_character_string_you_generate_yourself

Deployment

You can, if you want to (but I wouldn't), run mailer like this:

$ go run main/app.go

or build mailer and run it:

$ go build -o mailer main/app.go
$ ./mailer

Also note that if you do this you will probably want a .env file in this repo or adjecent to the executable.

Docker

Now for the cool way to run mailer you will use docker.
Keep in mind when using the docker image that you will need to mount the keys.toml file to /app/keys.toml.
Also keep in mind that in docker you can set the env variables with -e when running or by mounting the .env file to /app/.env.
First of all build the image with:

$ make build

Or the more customizable way:

$ sudo docker build -t mailer:latest .

After you built the image you can run it in docker:
$ sudo docker run -v path/to/your/keys.toml:/app/keys.toml -v path/to/your/.env:/app/.env --network="host" -d mailer:latest

Great you now are a mailer pro. Good luck mailing people!