gohog

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 6 Imported by: 0

README

go-hog a MailHog client

Go Reference

Go Client for mailhog: https://github.com/mailhog/MailHog

MailHog is a convenient test utility for email integration

This client provides a simple way to interact with Mailhog's API. To use it, ensure Mailhog is running. You can quickly set it up using the provided docker-compose file. Run in the project root:

docker compose up

Then test it is working by running;

go test

Go install:

go get github.com/latebit-io/go-hog

Documentation

Overview

Package gohog is a client library to interact with and consume mailhog's api https://github.com/mailhog/MailHog mailhog is very useful when testing email integration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	Headers Headers `json:"headers"`
	Body    string  `json:"body"`
	Size    int     `json:"size"`
	Mime    Mime    `json:"mime"`
}

Content of the email the Mime parts contain the content

type GoHog

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

func NewGoHogClient

func NewGoHogClient(url string, client *http.Client) *GoHog

NewGoHogClient creates a mailhog client

func (*GoHog) Delete

func (h *GoHog) Delete(id string) error

Delete this will delete a email message from mailhog by id Example id: eZVH3mSvQl9oWzIc4U1j1zWO8TWFWNv123iPrS0sOkE=@mailhog.example

func (*GoHog) DeleteAll

func (h *GoHog) DeleteAll() error

DeleteAll deletes all email messages on the server

func (*GoHog) Message

func (h *GoHog) Message(id string) (Message, error)

Message will return a single email message by id Example id: eZVH3mSvQl9oWzIc4U1j1zWO8TWFWNv123iPrS0sOkE=@mailhog.example

func (*GoHog) Messages

func (h *GoHog) Messages(start, limit int) (Messages, error)

Messages will return email messages between the start and limit

func (*GoHog) Search

func (h *GoHog) Search(searchType, query string, start, limit int) (Messages, error)

Search will search for messages by searchType using constants searchFrom, searchTo, and searchContains you can limit how many email messages will be returned query field is string that will be searched for in the email message

type Headers

type Headers struct {
	ContentId               []string `json:"content-id"`
	ContentDisposition      []string `json:"content-disposition"`
	ContentTransferEncoding []string `json:"content-transfer-encoding"`
	ContentType             []string `json:"content-type"`
	Date                    []string `json:"date"`
	From                    []string `json:"from"`
	MimeVersion             []string `json:"mime-version"`
	MessageId               []string `json:"message-id"`
	Received                []string `json:"received"`
	ReturnPath              []string `json:"return-path"`
	Subject                 []string `json:"subject"`
	To                      []string `json:"to"`
}

Headers metadata about the email message

type Message

type Message struct {
	Id      string    `json:"id"`
	From    Path      `json:"from"`
	To      []Path    `json:"to"`
	Content Content   `json:"content"`
	Created time.Time `json:"created"`
	Mime    Mime      `json:"mime"`
	Raw     Raw       `json:"raw"`
}

Message is used to represent a single email message

func (*Message) FromAddress

func (m *Message) FromAddress() string

FromAddress convenience method to get the from email address

func (*Message) Subject

func (m *Message) Subject() string

Subject convenience method to get the email subject

func (*Message) ToAddresses

func (m *Message) ToAddresses() []string

ToAddresses convenience method to get the to email addresses

type Messages

type Messages struct {
	Total int       `json:"total"`
	Count int       `json:"count"`
	Start int       `json:"start"`
	Items []Message `json:"items"`
}

Messages a struct the will contain a list of messages used for search and messages endpoint

type Mime

type Mime struct {
	Parts []Content
}

Mime email content parts, can be text or rich content

type Path

type Path struct {
	Relays  []string `json:"relays"`
	Mailbox string   `json:"mailbox"`
	Domain  string   `json:"domain"`
	Params  string   `json:"params"`
}

Path used to represent an SMTP forward or return path

type Raw

type Raw struct {
	From string   `json:"from"`
	To   []string `json:"to"`
	Date string   `json:"date"`
	Helo string   `json:"helo"`
}

Raw information about the email

Jump to

Keyboard shortcuts

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