A Go client library for the Shoutbox email service, supporting both REST API and SMTP implementations.
go get github.com/shoutboxnet/shoutbox-go
Create a .env
file based on the template:
make env-template # Creates .env.template
cp .env.template .env
Then edit .env
with your credentials:
SHOUTBOX_API_KEY=your_api_key_here
[email protected]
[email protected]
make help # Show available commands
make build # Build the main program
make run # Run the main program (requires env vars)
make test # Run tests (requires env vars)
make run-rest # Run REST API example
make run-smtp # Run SMTP example
make clean # Clean build artifacts
make env-template # Create .env.template file
package main
import (
"context"
"log"
"os"
"github.com/shoutboxnet/shoutbox-go/shoutbox"
)
func main() {
client := shoutbox.NewClient(os.Getenv("SHOUTBOX_API_KEY"))
req := &shoutbox.EmailRequest{
From: "[email protected]",
To: "[email protected]",
Subject: "Hello World",
HTML: "<h1>Welcome!</h1>",
}
err := client.SendEmail(context.Background(), req)
if err != nil {
log.Fatal(err)
}
}
package main
import (
"log"
"os"
"github.com/shoutboxnet/shoutbox-go/shoutbox"
)
func main() {
client := shoutbox.NewSMTPClient(os.Getenv("SHOUTBOX_API_KEY"))
msg := &shoutbox.EmailMessage{
From: "[email protected]",
To: []string{"[email protected]"},
Subject: "Hello World",
HTML: "<h1>Welcome!</h1>",
}
err := client.SendEmail(msg)
if err != nil {
log.Fatal(err)
}
}
attachment, err := shoutbox.NewAttachmentFromFile("document.pdf")
if err != nil {
log.Fatal(err)
}
msg := &shoutbox.EmailMessage{
From: "[email protected]",
To: []string{"[email protected]"},
Subject: "Document Attached",
HTML: "<h1>Please find the document attached</h1>",
Attachments: []shoutbox.Attachment{attachment},
}
- REST API and SMTP support
- File attachments
- Custom headers
- Reply-to address
- Sender name
- Email validation
- Context support (REST API)
- Comprehensive testing
Set up environment variables in .env
file and run:
make test
Check the examples
directory for complete usage examples:
examples/rest
: REST API implementation exampleexamples/smtp
: SMTP implementation example with attachments
Run examples using:
make run-rest # Run REST API example
make run-smtp # Run SMTP example
- 60 requests per minute per API key
- Maximum attachment size: 10MB
- Maximum recipients per email: 50
MIT License