Mail
A small beta Go module for sending HTML email through different providers.
The current implementation supports:
- SMTP
- AWS SES v2
- Oracle Cloud Infrastructure Email Delivery through SMTP
This project is intentionally basic right now. It provides a shared sender interface, simple YAML configuration loading, message validation, and provider-specific senders.
Requirements
- Go 1.26.4 or newer, as declared in
go.mod
- Provider credentials for the mail backend you want to use
Installation
go get github.com/more-shubham/mail
Configuration
Create a config.yaml file:
app:
name: mail
environment: development
mail:
type: smtp
from: no-reply@example.com
smtp:
host: localhost
port: 1025
username: ""
password: ""
ses:
region: us-east-1
oci:
host: smtp.email.us-ashburn-1.oci.oraclecloud.com
port: 587
username: ""
password: ""
Set mail.type to one of:
SMTP
SMTP requires:
mail.from
mail.smtp.host
mail.smtp.port
username and password are optional. If either value is set, the SMTP sender uses plain authentication.
AWS SES
SES requires:
mail.from
mail.ses.region
AWS credentials are loaded with the default AWS SDK configuration chain, so environment variables, shared config files, roles, and other standard AWS credential sources can be used.
OCI Email Delivery
OCI requires:
mail.from
mail.oci.host
mail.oci.port
mail.oci.username
mail.oci.password
OCI Email Delivery is sent through SMTP using plain authentication.
Usage
Load and validate configuration:
package main
import (
"log"
mail "github.com/more-shubham/mail"
"github.com/more-shubham/mail/config"
)
func main() {
appConfig, err := config.Load("config.yaml")
if err != nil {
log.Fatal(err)
}
if err := mail.Init(appConfig); err != nil {
log.Fatal(err)
}
if err := mail.Send("user@example.com", "Welcome", "<h1>Hello</h1>"); err != nil {
log.Fatal(err)
}
}
mail.Init validates the shared mail config, validates the selected provider config, and initializes the matching sender.
All providers implement:
type Sender interface {
Send(to string, subject string, html string) error
}
Project Structure
config/ YAML config loading and validation
message/ Email validation and HTML MIME message building
provider/ SMTP, SES, and OCI sender implementations
sender/ Shared Sender interface
main.go Package documentation
init.go Public Init and Send helpers
Current Limitations
- Only HTML email bodies are supported.
- Only one recipient is supported per
Send call.
- No attachments, CC, BCC, reply-to, or templates are implemented yet.
- The module is still beta and the public API may change.
Development
Run tests:
go test ./...
Code of Conduct
Participation in this project is covered by the Code of Conduct.
License
This project is open source under the MIT License.