Thanks to visit codestin.com
Credit goes to pkg.go.dev

smtpd

package module
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 8 Imported by: 0

README

smtpd-go

Continuous Integration GoDoc Go Report Card

The official SMTPD Go client library.

Supported versions

The current version is v0.1

Please use go modules and import via github.com/smtpd-dev/go-smtpd/v0.1.

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference stripe-go in a Go program with import:

import (
    "github.com/smtpd-dev/smtpd-go/v0.1"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the stripe-go module automatically.

Alternatively, you can also explicitly go get the package into a project:

go get -u github.com/smtpd-dev/smtpd-go/v0.1

Usage

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "github.com/joho/godotenv"
    smtpd "github.com/smtpd-dev/smtpd-go/v0.1"
    "log"
    "os"
)

func main() {
    err := godotenv.Load()
    if err != nil {
        log.Fatal("Error loading .env file")
    }

    key := os.Getenv("API_KEY")
    secret := os.Getenv("API_SECRET")
    client := smtpd.New(key, secret)

    p, err := client.GetAllProfiles()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(PrettyJSON(p))
}

func PrettyJSON(input interface{}) string {
    b, err := json.Marshal(input)
    if err != nil {
        log.Fatal(err)
    }

    var prettyJSON bytes.Buffer
    err = json.Indent(&prettyJSON, b, "", "\t")
    if err != nil {
        log.Fatal(err)
    }
    return string(prettyJSON.Bytes())
}

Issues

  • None

Development

Pull requests from the community are welcome. If you submit one, please keep the following guidelines in mind:

  1. Code must be go fmt compliant.
  2. All types, structs and funcs should be documented.
  3. Ensure that make lint ** make test succeeds.

Test

Before running the tests, make sure to grab all of the package's dependencies:

go get -t -v

Run all tests:

make test

For any requests, bug or comments, please [open an issue][issues] or [submit a pull request][pulls].

Documentation

Index

Constants

View Source
const (
	HeaderAuthorization = "Authorization"
	HeaderContentType   = "Content-Type"
	HeaderUserAgent     = "User-Agent"
)

Headers

View Source
const (
	ContentTypeJson string = "application/json"
)

ContentType

Variables

View Source
var (
	// ErrInvalidCredentials is return when the api key & secret are invalid
	ErrInvalidCredentials = errors.New("api key OR secret is invalid")

	// ErrResourceNotFound is return when the resource is not found
	ErrResourceNotFound = errors.New("resource not found")
)

Functions

This section is empty.

Types

type Client

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

Client -

func New

func New(key, secret string) *Client

New returns a new SMTPD instance

func (*Client) Authenticate

func (c *Client) Authenticate() error

func (*Client) CreateProfile

func (c *Client) CreateProfile(profile *CreateSendingProfile) (SendingProfile, error)

CreateProfile creates a profile

func (*Client) GetAllProfiles

func (c *Client) GetAllProfiles() ([]SendingProfile, error)

GetAllProfiles retrieves all email sending profiles

func (*Client) GetProfileByID

func (c *Client) GetProfileByID(id string) (SendingProfile, error)

GetProfileByID retrieves an email sending profile by ID

func (*Client) GetProfileByName

func (c *Client) GetProfileByName(name string) (SendingProfile, error)

GetProfileByName retrieves an email sending profile by name

func (*Client) SendBasic

func (c *Client) SendBasic(message SendBasicMessage) (SendBasicDetailedResponse, error)

SendBasic sends a transactional email

type CreateSendingProfile

type CreateSendingProfile struct {
	ProfileName               string `json:"profile_name"`
	SendingDomain             string `json:"sending_domain"`
	LinkDomain                string `json:"link_domain"`
	LinkDomainDefaultRedirect string `json:"link_domain_default_redirect"`
	BounceDomain              string `json:"bounce_domain"`
}

CreateSendingProfile represents the request payload to create a sending profile.

type Credentials

type Credentials struct {
	Username string
	Password string
}

type DomainRecords

type DomainRecords struct {
	Name            string `json:"name"`
	Type            string `json:"type"`
	Value           string `json:"value"`
	ValidationState string `json:"validation_state"`
}

DomainRecords is the DKIM records for a domain

type HTTP

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

HTTP struct

func (*HTTP) BuildEndpointWithQueryParameters

func (h *HTTP) BuildEndpointWithQueryParameters(endpoint string, parameters map[string]string) (string, error)

BuildEndpointWithQueryParameters add parameters to endpoint URL

func (*HTTP) Delete

func (h *HTTP) Delete(endpoint string, headers map[string]string) ([]byte, int, error)

Delete http call

func (*HTTP) Get

func (h *HTTP) Get(endpoint string, headers map[string]string) ([]byte, int, error)

Get http call

func (*HTTP) Post

func (h *HTTP) Post(endpoint string, payload []byte, headers map[string]string) ([]byte, int, error)

Post http call

func (*HTTP) PostWithBasicAuth

func (h *HTTP) PostWithBasicAuth(endpoint string, credentials Credentials, payload []byte, headers map[string]string) ([]byte, int, error)

PostWithBasicAuth http call

func (*HTTP) Put

func (h *HTTP) Put(endpoint string, payload []byte, headers map[string]string) ([]byte, int, error)

Put http call

type OauthTokenResponse

type OauthTokenResponse struct {
	TokenType    string   `json:"token_type"`
	AccessToken  string   `json:"access_token"`
	RefreshToken string   `json:"refresh_token"`
	ExpiresIn    int      `json:"expires_in"`
	Scope        []string `json:"scope"`
}

OauthTokenResponse -

type RefreshTokenRequest

type RefreshTokenRequest struct {
	RefreshToken string `json:"refresh_token"`
}

RefreshTokenRequest is contains a RefreshToken used to revoke a RefreshToken OR refresh an AccessToken

type SendBasicDetailedResponse

type SendBasicDetailedResponse struct {
	SendID                string   `json:"send_id"`
	SendKey               string   `json:"send_key"`
	SendingProfileID      string   `json:"sending_profile_id"`
	FromEmailAddress      string   `json:"from_email_address"`
	FromName              string   `json:"from_name"`
	RecipientEmailAddress string   `json:"recipient_email_address"`
	RecipientName         string   `json:"recipient_name"`
	Subject               string   `json:"subject"`
	OpenTracking          bool     `json:"open_tracking"`
	ClickTracking         bool     `json:"click_tracking"`
	Tags                  []string `json:"tags"`
	State                 string   `json:"state"`
	StateCategory         string   `json:"state_category"`
	Error                 string   `json:"error,omitempty"`
	CreatedAtUtc          int64    `json:"created_at_utc"`
	ModifiedAtUtc         int64    `json:"modified_at_utc"`
}

SendBasicDetailedResponse after a message has been accepted

type SendBasicMessage

type SendBasicMessage struct {
	RecipientEmailAddress string   `json:"recipient_email_address"`
	RecipientName         string   `json:"recipient_name"`
	FromEmailAddress      string   `json:"from_email_address"`
	FromName              string   `json:"from_name"`
	ReplyTo               string   `json:"reply_to"`
	Subject               string   `json:"subject"`
	ContentHTML           string   `json:"content_html"`
	ContentText           string   `json:"content_text"`
	OpenTracking          bool     `json:"open_tracking"`
	ClickTracking         bool     `json:"click_tracking"`
	Tags                  []string `json:"tags"`
}

SendBasicMessage is used to send an email

type SendingProfile

type SendingProfile struct {
	SendingProfileID          string `json:"profile_id"`
	ProfileName               string `json:"profile_name"`
	SendingDomain             string `json:"sending_domain"`
	LinkDomain                string `json:"link_domain"`
	LinkDomainDefaultRedirect string `json:"link_domain_default_redirect"`
	BounceDomain              string `json:"bounce_domain"`
	State                     string `json:"state"`
	CreatedAtUtc              int64  `json:"created_at_utc"`
	ModifiedAtUtc             int64  `json:"modified_at_utc"`
}

SendingProfile is return when doing a lookup

type SendingProfileSetup

type SendingProfileSetup struct {
	SendingProfileID string          `json:"profile_id"`
	ProfileName      string          `json:"profile_name"`
	Records          []DomainRecords `json:"dns_records"`
	State            string          `json:"state"`
	CreatedAtUtc     int64           `json:"created_at_utc"`
	ModifiedAtUtc    int64           `json:"modified_at_utc"`
}

SendingProfileSetup is return when doing a lookup

Directories

Path Synopsis
cmd
cli command

Jump to

Keyboard shortcuts

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