logpacker / mailer

0 stars 2 forks source link

Dependencies

Development

Build & Deploy

cd $GOPATH/src
mkdir -p github.com/logpacker
cd github.com/logpacker
git clone git@github.com:logpacker/mailer.git
cd mailer
glide i
go build -ldflags "-X main.Version=$(git rev-parse HEAD)" -o mailer_api cmd/api/main.go
go build -ldflags "-X main.Version=$(git rev-parse HEAD)" -o mailer_daemon cmd/daemon/main.go

Usage and Flags

./mailer_api -h
./mailer_daemon -h

How does it work

Mail statuses:

CURL Example

Retreive token
curl -H "Content-Type: application/json" -XGET 'http://localhost:80/v1/token?api_key=XXX'
Send email
curl -H "Content-Type: application/json" -XPOST 'http://localhost:80/v1/send?token=XXX&api_key=XXX' \
-d '{"from": {"email": "mailer@logpacker.com", "name": "LogPacker"}, "to": {"email": "alexander.plutov@gmail.com"}, "subject": "Verify your email address", "Body": "Thank you for the registration.<br/>Now please confirm it.", "url_unsubscribe": "https://logpacker.com"}'

Go Client example

package main

import (
    "github.com/logpacker/mailer/pkg/client"
)

func main() {
    // Error handling skipped for better readability
    c, _ := client.New(client.Config{
        URL:    "http://127.0.0.1:80",
        APIKey: "secret",
    })

    c.SendEmail(client.Email{
        From: &client.Address{
            Email: "mailer@logpacker.com",
            Name:  "LogPacker",
        },
        To: &client.Address{
            Email: "alexander.plutov@gmail.com",
        },
        Subject:        "Verify your email address",
        Body:           "Thank you for the registration.<br/>Now please confirm it.",
        URLUnsubscribe: "https://logpacker.com",
    })
}