CREATE DATABASE mailer CHARACTER SET utf8 COLLATE utf8_general_ci;
(import db/schema.sql
)go generate cmd/api/main.go
go test ./pkg/... -v -cover
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
./mailer_api -h
./mailer_daemon -h
Sender
sends request to Mailer API
to save mail into the queueMailer Daemon
sends emails from queue to Recepient
via SMTP and updates DBMail statuses:
curl -H "Content-Type: application/json" -XGET 'http://localhost:80/v1/token?api_key=XXX'
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"}'
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",
})
}