Skip to content

Go

Go Version Build Status License: MIT

Go SDK for Poodle’s email sending API.

Install the SDK using Go modules:

Terminal window
go get github.com/usepoodle/poodle-go
package main
import (
"fmt"
"log"
"github.com/usepoodle/poodle-go"
)
func main() {
// Initialize the client
client := poodle.NewClient("your_api_key_here")
// Send an email
response, err := client.SendHTML(
"Hello from Poodle!",
"<h1>Hello World!</h1><p>This is a test email.</p>",
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Email sent! Success: %t, Message: %s\n",
response.Success, response.Message)
}
  • Simple and intuitive API
  • HTML and plain text email support
  • Comprehensive error handling
  • Built-in input validation
  • Go 1.20+ support
  • Goroutine-safe client design
  • Extensive test suite
  • Zero external dependencies

Set your API key in one of these ways:

1. Pass directly to constructor:

client := poodle.NewClient("your_api_key_here")

2. Use environment variable:

Terminal window
export POODLE_API_KEY=your_api_key_here
client := poodle.NewClientFromEnv()

3. Use Configuration object:

config := &poodle.Config{
APIKey: "your_api_key_here",
BaseURL: "https://api.usepoodle.com",
Timeout: 30 * time.Second,
ConnectTimeout: 10 * time.Second,
Debug: true,
}
client := poodle.NewClientWithConfig(config)
VariableDefaultDescription
POODLE_API_KEY-Your Poodle API key
POODLE_BASE_URLhttps://api.usepoodle.comAPI base URL
POODLE_TIMEOUT30sRequest timeout
POODLE_CONNECT_TIMEOUT10sConnection timeout
POODLE_DEBUGfalseEnable debug logging
client := poodle.NewClient("your_api_key")
// HTML email
response, err := client.SendHTML(
"Welcome!",
"<h1>Welcome to our service!</h1>",
)
// Plain text email
response, err := client.SendText(
"Welcome!",
"Welcome to our service!",
)
// Both HTML and text
response, err := client.SendWithBoth(
"Welcome!",
"<h1>Welcome!</h1>",
"Welcome!",
)
email := &poodle.Email{
Subject: "Welcome Email",
HTML: "<h1>Hello!</h1><p>Welcome to our service!</p>",
Text: "Hello! Welcome to our service!",
}
response, err := client.Send(email)
if err != nil {
log.Fatal(err)
}
if response.Success {
fmt.Println("Email queued successfully!")
}
response, err := client.SendHTML(
"Test Email",
"<h1>Hello!</h1>",
)
if err != nil {
switch e := err.(type) {
case *poodle.ValidationError:
fmt.Printf("Validation error: %s\n", e.Error())
for field, errors := range e.Errors {
fmt.Printf(" %s: %v\n", field, errors)
}
case *poodle.AuthenticationError:
fmt.Printf("Authentication failed: %s\n", e.Error())
case *poodle.RateLimitError:
fmt.Printf("Rate limit exceeded. Retry after: %d seconds\n", e.RetryAfter)
case *poodle.NetworkError:
fmt.Printf("Network error: %s\n", e.Error())
default:
fmt.Printf("Unknown error: %s\n", err.Error())
}
return
}
fmt.Printf("Email sent successfully! Message: %s\n", response.Message)

Creates a new client with the provided API key.

Creates a new client using environment variables.

NewClientWithConfig(config *Config) *Client

Section titled “NewClientWithConfig(config *Config) *Client”

Creates a new client with custom configuration.

Send(email *Email) (*EmailResponse, error)

Section titled “Send(email *Email) (*EmailResponse, error)”

Sends an email using the Email model.

SendHTML(from, to, subject, html string) (*EmailResponse, error)

Section titled “SendHTML(from, to, subject, html string) (*EmailResponse, error)”

Sends an HTML email.

SendText(from, to, subject, text string) (*EmailResponse, error)

Section titled “SendText(from, to, subject, text string) (*EmailResponse, error)”

Sends a plain text email.

SendWithBoth(from, to, subject, html, text string) (*EmailResponse, error)

Section titled “SendWithBoth(from, to, subject, html, text string) (*EmailResponse, error)”

Sends an email with both HTML and text content.

type Email struct {
From string `json:"from"`
To string `json:"to"`
Subject string `json:"subject"`
HTML string `json:"html,omitempty"`
Text string `json:"text,omitempty"`
}
type EmailResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
}
type Config struct {
APIKey string
BaseURL string
Timeout time.Duration
ConnectTimeout time.Duration
Debug bool
}

The SDK provides specific error types for different scenarios:

  • ValidationError - Invalid request data (400)
  • AuthenticationError - Invalid or missing API key (401)
  • AccountSuspendedError - Account suspended (403)
  • SubscriptionError - Subscription issues (402)
  • RateLimitError - Rate limit exceeded (429)
  • NetworkError - Network connectivity issues

Each error type provides additional context and methods for handling specific scenarios.

Contributions are welcome! Please read our Contributing Guide for details on the process for submitting pull requests.

This project is licensed under the MIT License - see the LICENSE file for details.