postmark

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 8 Imported by: 0

README

Postmark

Postmark is a Client SDK for the Postmark API

Usage

New
func ExampleNew() {
	testClient = New(testAPIKey)
}
Client.Email
func ExampleClient_Email() {
	var err error
	e := MakeEmail("from@email.com", "to@email.com", "test email", "<p>Hello world</p>")

	var resp EmailResponse
	if resp, err = testClient.Email(e); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Response!", resp)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyToAddress is returned when an "to" address is empty
	ErrEmptyToAddress = errors.New("invalid \"to\" address, cannot be empty")
	// ErrEmptyFromAddress is returned when an "from" address is empty
	ErrEmptyFromAddress = errors.New("invalid \"from\" address, cannot be empty")
	// ErrEmptyBody is returned when an HTML body and text body are empty
	ErrEmptyBody = errors.New("invalid body, both HTML body and text body cannot be empty")
)

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	// Name of attachment
	Name string `json:"Name"`
	// Content of attachment
	Content string `json:"Content"`
	// Content type of attachment
	ContentType string `json:"ContentType"`
	// Content ID of attachment
	ContentID string `json:"ContentID,omitempty"`
}

Attachment represents an email attachment

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages the request to the Postmark API

func New

func New(apiKey string) *Client

New will initialize and return a new Client

Example
testClient = New(testAPIKey)

func (*Client) Email

func (c *Client) Email(e Email) (resp EmailResponse, err error)

Email will send an email

Example
var err error
e := MakeEmail("from@email.com", "to@email.com", "test email", "<p>Hello world</p>")

var resp EmailResponse
if resp, err = testClient.Email(e); err != nil {
	log.Fatal(err)
}

fmt.Println("Response!", resp)

func (*Client) EmailWithTemplate

func (c *Client) EmailWithTemplate(e EmailWithTemplate) (resp EmailResponse, err error)

Email will send an email

type Email

type Email struct {
	// Sender of email
	From string `json:"From"`
	// Receiver of email
	To string `json:"To"`
	// Additional public receivers of email
	Cc string `json:"Cc"`
	// Additional private receivers of email
	Bcc string `json:"Bcc"`

	// Email address to reply to
	ReplyTo string `json:"ReplyTo"`

	// Email subject
	Subject string `json:"Subject,omitempty"`

	// Email body as HTML
	HTMLBody string `json:"HtmlBody,omitempty"`
	// Email body as text
	TextBody string `json:"TextBody,omitempty"`

	TrackOpens bool   `json:"TrackOpens"`
	TrackLinks string `json:"TrackLinks,omitempty"`

	Attachments []Attachment `json:"Attachments,omitempty"`
	Headers     []Header     `json:"Headers,omitempty"`

	Metadata      *Metadata `json:"Metadata,omitempty"`
	MessageStream string    `json:"MessageStream,omitempty"`
	Tag           string    `json:"Tag,omitempty"`
}

Email represents the request body for sending an email

func MakeEmail

func MakeEmail(from, to, subject, htmlBody string) (e Email)

MakeEmail will initialize an Email value

func (*Email) Validate

func (e *Email) Validate() (err error)

Validate will validate an email

type EmailResponse

type EmailResponse struct {
	// The "to" address of the Email
	To string `json:"To"`
	// Postmark Message ID for created Email
	MessageID string `json:"MessageID"`

	// Time at which the email send request was submitted (RFC3339)
	SubmittedAt time.Time `json:"SubmittedAt"`
}

EmailResponse is the response from the Postmark API to an Email request

type EmailWithTemplate

type EmailWithTemplate struct {
	Email

	TemplateID    int    `json:"TemplateId"`
	TemplateAlias string `json:"TemplateAlias"`

	TemplateModel map[string]interface{} `json:"TemplateModel"`

	InlineCSS bool `json:"InlineCss"`
}

type Error

type Error struct {
	// ErrorCodes as specified within the Postmark API Documentation (https://postmarkapp.com/developer/api/overview#error-codes)
	ErrorCode int64 `json:"ErrorCode"`
	// Human-readable error message
	Message string `json:"Message"`
}

Error represents an error response from the API

func (Error) Error

func (e Error) Error() string
type Header struct {
	// Name of header
	Name string `json:"Name"`
	// Header value
	Value string `json:"Value"`
}

Header represents a header value

type Metadata

type Metadata struct {
	Color    string `json:"color"`
	ClientID string `json:"client-id"`
}

Metadata represents metadata information

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL