Skip to main content

Go SDK

The jetemail-go module is the official Go SDK for JetEmail transactional email (MIT license, Go 1.21+). Create a transactional API key in the dashboard: OutboundKeys → Add API key. Use that key with the SDK.

Installation

go get github.com/jetemail/jetemail-go

Quick start

package main

import (
    "fmt"
    "github.com/jetemail/jetemail-go"
)

func main() {
    client := jetemail.New("your-transactional-api-key")

    result, err := client.Email.Send(&jetemail.SendEmailOptions{
        From:    "Your App <[email protected]>",
        To:      "[email protected]",
        Subject: "Welcome!",
        HTML:    "<h1>Welcome!</h1>",
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(result.ID)
}
Use a From address on a verified domain (see Getting started).

Constructor

// API key string
client := jetemail.New("your-transactional-api-key")

// Or with options
client := jetemail.New("your-transactional-api-key", jetemail.WithBaseURL("https://api.jetemail.com"))

client.Email.Send(options)

Send a single email.
FieldRequiredDescription
FromSender, e.g. "Name <[email protected]>"
ToRecipient(s), string or slice (max 50)
SubjectSubject line
HTML*HTML body (need HTML and/or Text)
Text*Plain text (need HTML and/or Text)
CC, BCC, ReplyToRecipients (max 50 each)
HeadersCustom headers map
AttachmentsAttachments (max 40MB total)
Response shape: SendEmailResponse{ ID string, Response string }.

client.Batch.Send(emails)

Send up to 100 emails in one request. Returns Summary (Total, Successful, Failed) and Results per message.
result, err := client.Batch.Send([]*jetemail.SendEmailOptions{
    {
        From:    "[email protected]",
        To:      "[email protected]",
        Subject: "Hello Alice",
        HTML:    "<p>Hi Alice!</p>",
    },
    {
        From:    "[email protected]",
        To:      "[email protected]",
        Subject: "Hello Bob",
        HTML:    "<p>Hi Bob!</p>",
    },
})

Attachments

result, err := client.Email.Send(&jetemail.SendEmailOptions{
    From:    "[email protected]",
    To:      "[email protected]",
    Subject: "Invoice",
    HTML:    "<p>Please find your invoice attached.</p>",
    Attachments: []jetemail.Attachment{
        jetemail.AttachmentFromPath("/path/to/invoice.pdf"),
        jetemail.AttachmentFromContent([]byte("Hello World"), "hello.txt"),
    },
})

Error handling

result, err := client.Email.Send(&jetemail.SendEmailOptions{...})
if err != nil {
    var apiErr *jetemail.JetEmailError
    if errors.As(err, &apiErr) {
        fmt.Println(apiErr.StatusCode, apiErr.Message, apiErr.Response)
    }
}
Common status codes: 400 invalid request, 401 bad/missing API key, 500 server error.
For additional examples and the full option list, see the GitHub repository. REST details: API reference.