The official Golang client for sending emails via the SendSculpt Mailer API.
Installation
Retrieve the module using .go get:
go get github.com/sendsculpt/sendsculpt-sdk-go
Quick Start
Initialize the client with your API Key.
package main
import (
"fmt"
"log"
"github.com/sendsculpt/sendsculpt-sdk-go"
)
func main() {
client := sendsculpt.NewClient("your-api-key")
req := &sendsculpt.SendEmailRequest{
To: []string{"recipient@example.com"},
Subject: "Welcome to SendSculpt!",
FromEmail: "noreply@yourdomain.com",
BodyHTML: sendsculpt.StringPtr("<h1>Hello!</h1><p>This is a test email.</p>"),
}
response, err := client.SendEmail(req)
if err != nil {
log.Fatalf("Failed to send email: %v", err)
}
fmt.Printf("Email queued successfully! Message ID: %s\n", response.MessageID)
}
Advanced Usage
Send emails utilizing SendSculpt Templates and auto-encoded Attachments.
package main
import (
"fmt"
"log"
"github.com/sendsculpt/sendsculpt-sdk-go"
)
func sendInvoiceEmail(client *sendsculpt.Client) {
req := &sendsculpt.SendEmailRequest{
To: []string{"john@doe.com"},
Subject: "Your Monthly Invoice",
FromEmail: "billing@yourdomain.com",
TemplateID: sendsculpt.StringPtr("uuid-of-your-template"),
TemplateData: map[string]interface{}{
"first_name": "John",
"invoice_amount": "49.99",
},
CC: []string{"finance@yourdomain.com"},
Attachments: []sendsculpt.Attachment{
{
Filename: "invoice.pdf",
FilePath: "/path/to/invoice.pdf", // Auto-converted to Base64
MimeType: "application/pdf",
},
},
}
res, err := client.SendEmail(req)
if err != nil {
log.Fatalf("Error: %v", err)
}
fmt.Println("Message ID:", res.MessageID)
}
For local development, you can include the target baseUrl as an optional secondary argument when instantiating:
sendsculpt.NewClient("your-api-key", "https://api.sendsculpt.com/api/v1").