Skip to content

usesend/usesend-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UseSend Go SDK

A Go client for the UseSend API.

Installation

go get github.com/usesend/usesend-go

Usage

package main

import (
    "context"
    "log"

    usesend "github.com/usesend/usesend-go"
)

func main() {
    client, err := usesend.NewClient("us_123")
    if err != nil {
        log.Fatal(err)
    }

    resp, errResp, err := client.Emails.Send(context.Background(), usesend.SendEmailPayload{
        To:   []string{"[email protected]"},
        From: "[email protected]",
        Subject: "Hello",
        HTML:    "<p>Hi there!</p>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if errResp != nil {
        log.Fatalf("api error: %s", errResp.Message)
    }

    log.Printf("email queued with id %s", resp.EmailID)
}

API keys can also be supplied via the USESEND_API_KEY environment variable.

Options

  • WithBaseURL(url string): Override the base API URL (e.g. for self-hosting).
  • WithHTTPClient(*http.Client): Provide a custom HTTP client.

Notes:

  • The default HTTP client uses a 30s timeout.
  • Requests include a User-Agent: usesend-go header.

Contacts example

contact, apiErr, err := client.Contacts.Create(ctx, "contactBook_123", usesend.CreateContactPayload{
    Email: "[email protected]",
})
if err != nil { /* transport error */ }
if apiErr != nil { /* API error */ }
log.Println("contact id:", contact.ContactID)

About

go sdk for usesend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages