Skip to content

Commit 7d1676b

Browse files
committed
Update README + add examples
1 parent b7f8d65 commit 7d1676b

10 files changed

+90
-26
lines changed

.env.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SERVER_HOST=
22
SERVER_PORT=8080
33
SERVER_SHUTDOWN_TIMEOUT=5
4-
HTTP_TRACE_HEADER=X-Amzn-Trace-Id
4+
TRACEPARENT_HEADER=traceparent
55
SMTP_ADDR=smtp:1025
66
LOG_LEVEL=debug

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.gif filter=lfs diff=lfs merge=lfs -text

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.env
2+
coverage.txt

README.md

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
1-
# HTTP to SMTP
1+
# 📩 HTTP to SMTP
22

3-
[![docker image](https://img.shields.io/docker/v/eexit/http2smtp?label=docker-image&sort=date)](https://hub.docker.com/repository/docker/eexit/http2smtp) [![ci](https://github.com/eexit/http2smtp/workflows/build/badge.svg)](https://github.com/eexit/http2smtp/actions) [![codecov](https://codecov.io/gh/eexit/http2smtp/branch/master/graph/badge.svg?token=XH18EYLDLZ)](https://codecov.io/gh/eexit/http2smtp)
3+
[![version](https://img.shields.io/github/v/tag/eexit/http2smtp?label=version&logo=github&sort=semver)](https://github.com/eexit/http2smtp/releases) [![docker pull](https://img.shields.io/docker/pulls/eexit/http2smtp)](https://hub.docker.com/repository/docker/eexit/http2smtp) [![ci](https://github.com/eexit/http2smtp/workflows/build/badge.svg)](https://github.com/eexit/http2smtp/actions) [![codecov](https://codecov.io/gh/eexit/http2smtp/branch/master/graph/badge.svg?token=XH18EYLDLZ)](https://codecov.io/gh/eexit/http2smtp) [![license](https://img.shields.io/github/license/eexit/http2smtp)](https://github.com/eexit/http2smtp/blob/master/LICENSE)
44

5-
This small app allows to connect any HTTP-based vendor mailer to a SMTP server. Developped because of the lack of capability to test email sending thru APIs.
5+
An API proxies HTTP-backed vendor mailer calls to SMTP.
66

7-
### Supported vendors
8-
9-
- [SparkPost RFC 822 transmission](https://developers.sparkpost.com/api/transmissions/#transmissions-post-send-rfc822-content)
7+
Plug a MailHog or MailCatcher to API email sending vendors such as SparkPost, MailGun or Twilio SendGrid for testing purposes.
108

119
## Usage
1210

11+
See [examples](examples).
12+
13+
:zap: ProTip: for tracing purposes, this app kinda supports [W3C Trace Context recommendation](https://www.w3.org/TR/trace-context/). Configure the env var `TRACEPARENT_HEADER` and inject any trace into this header value. All log entries will be contextualized with the given value.
14+
1315
### Docker image
1416

1517
1. Checkout this repo or only copy the `.env.dist` and `docker-compose.yml` files
1618
1. Rename `.env.dist` into `.env`
17-
2. Update the values accordingly
18-
19-
```bash
20-
# Pull the images
21-
docker-compose pull
22-
# Up the stack
23-
docker-compose up http2smtp
24-
Creating http2smtp_smtp_1 ... done
25-
Creating http2smtp_http2smtp_1 ... done
26-
Attaching to http2smtp_http2smtp_1
27-
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","time":"2021-01-03T22:32:08Z","message":"app is starting"}
28-
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"time":"2021-01-03T22:32:08Z","message":"dialing to smtp server"}
29-
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","time":"2021-01-03T22:32:08Z","message":"listening on http:8080"}
30-
```
19+
1. Update the values accordingly
20+
1. Pull images and run `docker-compose up http2smtp`
3121

3222
## Vendor endpoints
3323

34-
### SparkPost
24+
### [SparkPost](https://developers.sparkpost.com/api/)
3525

3626
#### Inline transmission
3727

38-
_Not supported yet._
28+
API documentation: https://developers.sparkpost.com/api/transmissions/#transmissions-post-send-inline-content
29+
30+
_:warning: Not supported yet._
3931

4032
#### RFC 822 transmission
4133

42-
SparkPost documentation: https://developers.sparkpost.com/api/transmissions/#transmissions-post-send-rfc822-content
34+
API documentation: https://developers.sparkpost.com/api/transmissions/#transmissions-post-send-rfc822-content
4335

4436
POST /sparkpost/api/v1/transmissions
4537

46-
Basic validation is enforced, only the recipients list and the RFC 822 content are used.
38+
Basic validation is enforced, only the recipients list email and the RFC 822 content are used and mandatory.
39+
40+
## License
41+
42+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
43+
44+
## Contributors
4745

46+
![contributors](https://contrib.rocks/image?repo=eexit/http2smtp)

examples/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Examples
2+
3+
## Healthcheck
4+
5+
![healthcheck.gif](healthcheck.gif)
6+
7+
## SparkPost
8+
9+
- [RFC 822 transmissions](sparkpost_rfc822.md)
10+

examples/healthcheck.gif

+3
Loading

examples/sparkpost_rfc822.gif

+3
Loading

examples/sparkpost_rfc822.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"recipients":[
3+
{
4+
"address":{"email":"[email protected]"}
5+
}
6+
],
7+
"content":{
8+
"email_rfc822":"From: Test <[email protected]>\nTo: Bob <[email protected]>\nSubject: Hello world!\n\nHello world!"
9+
}
10+
}

examples/sparkpost_rfc822.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SparkPost RFC 822
2+
3+
API documentation: https://developers.sparkpost.com/api/transmissions/#transmissions-post-send-rfc822-content
4+
5+
![sparkpost_rfc822.gif](sparkpost_rfc822.gif)
6+
7+
Launch the API:
8+
9+
```bash
10+
docker-compose up http2smtp
11+
Creating http2smtp_smtp_1 ... done
12+
Creating http2smtp_http2smtp_1 ... done
13+
Attaching to http2smtp_http2smtp_1
14+
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","time":"2021-01-03T22:32:08Z","message":"app is starting"}
15+
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"time":"2021-01-03T22:32:08Z","message":"dialing to smtp server"}
16+
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","time":"2021-01-03T22:32:08Z","message":"listening on http:8080"}
17+
```
18+
19+
Send the example request:
20+
21+
```bash
22+
http POST :8080/sparkpost/api/v1/transmissions traceparent:$(openssl rand -hex 16) < sparkpost_rfc822.json
23+
```
24+
25+
Logs:
26+
27+
```bash
28+
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","time":"2021-01-04T00:24:27Z","message":"sending message"}
29+
http2smtp_1 | {"level":"debug","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","tos":["[email protected]"],"time":"2021-01-04T00:24:27Z","message":"executing transaction"}
30+
http2smtp_1 | {"level":"debug","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","from":"Test <[email protected]>","time":"2021-01-04T00:24:27Z","message":"sending MAIL FROM cmd"}
31+
http2smtp_1 | {"level":"debug","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","to":"[email protected]","time":"2021-01-04T00:24:27Z","message":"sending RCPT cmd"}
32+
http2smtp_1 | {"level":"debug","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","time":"2021-01-04T00:24:27Z","message":"sending DATA cmd"}
33+
http2smtp_1 | {"level":"debug","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","data":"From: Test <[email protected]>\nTo: Bob <[email protected]>\nSubject: Hello world!\n\nHello world!","time":"2021-01-04T00:24:27Z","message":"writing data"}
34+
http2smtp_1 | {"level":"debug","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","tos":["[email protected]"],"time":"2021-01-04T00:24:27Z","message":"transaction executed"}
35+
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","smtp":{"addr":"smtp:1025","id":"go:net/smtp"},"trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","accepted":1,"time":"2021-01-04T00:24:27Z","message":"message sent"}
36+
http2smtp_1 | {"level":"info","version":"v0.1.0+dev","trace_id":"304dfb8a7fbcfbdb1db373da9e39354a","verb":"POST","ip":"172.24.0.1","user_agent":"HTTPie/2.3.0","url":"/sparkpost/api/v1/transmissions","code":201,"size":97,"duration":3.273861,"time":"2021-01-04T00:24:27Z","message":"served request"}
37+
```

internal/env/env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Bag struct {
1212
// HTTPTraceHeader is a header that provides a unique per-request ID that will be
1313
// injected into all logs entries related to the same request. This is used to track
1414
// the a request trace within the underlying services
15-
HTTPTraceHeader string `envconfig:"HTTP_TRACE_HEADER"`
15+
HTTPTraceHeader string `envconfig:"TRACEPARENT_HEADER" default:"traceparent"`
1616
// SMTPAddr is the hostname:port config of the SMTP server the app forwards emails to
1717
SMTPAddr string `envconfig:"SMTP_ADDR" required:"true"`
1818
// LogLevel is the level of log generated by the app

0 commit comments

Comments
 (0)