A Go application for sending bulk emails from CSV files using SMTP with concurrent processing and retry logic.
- Bulk email sending from CSV files
- Concurrent processing with worker pools
- HTML email templates with dynamic variables
- Retry logic with exponential backoff
- Environment-based configuration
Click the image above to watch the demo video
- Go 1.25.1 or later
- SMTP server credentials
- CSV file with recipient data
git clone https://github.com/hereisSwapnil/go-mailer.git
cd go-mailer
go mod downloadCreate config/local.yaml:
smtp:
host: "smtp.gmail.com"
port: 587
username: "[email protected]"
password: "your-app-password"
from: "[email protected]"
templates:
test_email_template: "internal/templates/test_mail.tmpl"
data:
csv_file_path: "data/csv/recipients.csv"
retry:
max_retries: 3
initial_delay_seconds: 1
backoff_multiplier: 2.0
max_delay_seconds: 30Required columns: Name, Email
Optional columns: Any additional columns (e.g., Coupon, Discount) are available in templates.
Example:
Name, Email, Coupon
John Doe, [email protected], JOHN1000
Jane Smith, [email protected], JANE2000
Templates use Go's html/template package with two sections: subject and html.
Example (internal/templates/test_mail.tmpl):
{{define "subject"}}Thank you for joining, {{.Name}}. Here is your coupon{{end}}
{{define "html"}}
<!doctype html>
<html>
<body style="font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">
<p>Hello <strong>{{.Name}}</strong>,</p>
<p>Thank you for joining us. We are glad to welcome you.</p>
<p>Your coupon code is:</p>
<p style="font-size: 20px; font-weight: bold;">{{.Coupon}}</p>
<p>Enjoy your shopping.</p>
<p>Warm regards,<br />Go Mailer Team</p>
</body>
</html>
{{end}}Template variables: All CSV columns are available (e.g., {{.Name}}, {{.Email}}, {{.Coupon}}).
export ENV=local # Optional, defaults to "local"
go run cmd/go-mailer/main.goOr build and run:
go build -o go-mailer cmd/go-mailer/main.go
./go-mailer- Loads configuration from
config/{ENV}.yaml - Producer reads CSV and sends recipients to a channel
- Worker pool (10 workers) processes recipients concurrently
- Each worker renders templates and sends emails via SMTP
- Failed sends are retried with exponential backoff
go-mailer/
├── cmd/go-mailer/main.go
├── config/local.yaml
├── data/csv/recipients.csv
├── internal/
│ ├── config/config.go
│ ├── consumer/consumer.go
│ ├── producer/producer.go
│ ├── templates/test_mail.tmpl
│ └── types/types.go
├── go.mod
└── README.md




