Email sender using AWS SES with HTML/text templates support.
- Create
.env
fromexample.env
- Create your template in
templates
folder - Prepare
data.csv
:
EMAIL
user1@example.com
user2@example.com
- Run:
go run ./cmd/quick/main.go --data-file="data.csv" --email-sender="sender@email.com" --subject="Subject" --tmpl-file="templates/example.html"
You can run program without any flags
go run ./cmd/quick/main.go
Required params will be taken from data.csv
and .env
files.
Tip
Program supports flag -h
go run ./cmd/quick/main.go -h # Show all available options
Program logs all email sending attempts to .history.log
.
Data file (which is .csv) that defines email settings and template variables.
Advanced data.csv
example:
EMAIL,TEMPLATE_FILE,SUBJECT,name
example@example.com,templates/example.html,My Example subject,Dias1c
example@example.com,templates/example.txt,Text letter,MyName
example@example.com,,,
Explaining variable keys:
key | variable | description |
---|---|---|
EMAIL |
system | variable, recipient email |
TEMPLATE_FILE |
system | variable, path to template file |
SUBJECT |
system | variable, letter subject |
name |
user | variable |
Note
For the last row with empty columns, the values ​​for those columns will be taken from the program arguments
or env
file.
System reserved variables are named with capital letters. Each system variable has its own function.
key | type | function |
---|---|---|
EMAIL |
required | recipient email |
TEMPLATE_FILE |
optional | path to template file |
SUBJECT |
optional | letter subject |
SENDER_EMAIL |
optional | aws sender email |
SENDER_REGION |
optional | aws region |
All optional variable values ​​are taken from the arguments passed to the program or from the .env
file.
Variables that are not system keys will be used as variables for templates.
Program uses priority system to resolve conflicts when same parameter is set in multiple places:
Priority | Source | Example |
---|---|---|
High | Data file | data.csv : SUBJECT=Welcome |
Medium | Command flags | --subject="Hello" as flag on launch |
Low | .env file | SUBJECT=Hi in .env |
<h1>Welcome {{.name}}!</h1>
<p>Your activation code {{.code}} for {{.EMAIL}}</p>
--- {{.EMAIL}}
Dear {{.name}},
Your order #{{.orderId}} completed