mailosaur

package module
v0.0.0-...-feeef3c Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 11 Imported by: 0

README

Mailosaur - Go library ·

Mailosaur lets you automate email and SMS tests as part of software development and QA.

  • Unlimited test email addresses for all - every account gives users an unlimited number of test email addresses to test with.
  • End-to-end (e2e) email and SMS testing Allowing you to set up end-to-end tests for password reset emails, account verification processes and MFA/one-time passcodes sent via text message.
  • Fake SMTP servers Mailosaur also provides dummy SMTP servers to test with; allowing you to catch email in staging environments - preventing email being sent to customers by mistake.

Get Started

You can find the full Mailosaur documentation on the website.

If you get stuck, just contact us at support@mailosaur.com.

Installation
go mod init

Then, reference mailosaur-go via import:

import (
    "github.com/mailosaur/mailosaur-go"
)

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

go get -u github.com/mailosaur/mailosaur-go
API Reference

This library is powered by the Mailosaur email & SMS testing API. You can easily check out the API itself by looking at our API reference documentation or via our Postman or Insomnia collections:

Run in Postman

Creating an account

Create a free trial account for Mailosaur via the website.

Once you have this, navigate to the API tab to find the following values:

  • Server ID - Servers act like projects, which group your tests together. You need this ID whenever you interact with a server via the API.
  • Server Domain - Every server has its own domain name. You'll need this to send email to your server.
  • API Key - You can create an API key per server (recommended), or an account-level API key to use across your whole account. Learn more about API keys.

Test email addresses with Mailosaur

Mailosaur gives you an unlimited number of test email addresses - with no setup or coding required!

Here's how it works:

  • When you create an account, you are given a server.
  • Every server has its own Server Domain name (e.g. abc123.mailosaur.net)
  • Any email address that ends with @{YOUR_SERVER_DOMAIN} will work with Mailosaur without any special setup. For example:
    • build-423@abc123.mailosaur.net
    • john.smith@abc123.mailosaur.net
    • rAnDoM63423@abc123.mailosaur.net
  • You can create more servers when you need them. Each one will have its own domain name.

Can't use test email addresses? You can also use SMTP to test email. By connecting your product or website to Mailosaur via SMTP, Mailosaur will catch all email your application sends, regardless of the email address.

Usage

example_test.go

package emailtests

import (
  "fmt"
  "testing"
  "github.com/mailosaur/mailosaur-go"
)

func TestExample(t *testing.T) {
  // Available in the API tab of a server
  apiKey := "YOUR_API_KEY";
  serverId := "SERVER_ID";
  serverDomain := "SERVER_DOMAIN";

  m := mailosaur.New(apiKey);

  params := &mailosaur.MessageSearchParams {
    Server: serverId,
  }

  criteria := &mailosaur.SearchCriteria {
    SentTo: "anything@" + serverDomain,
  }

  email, err := m.Messages.Get(params, criteria)

  if (err != nil) {
    t.Error(err)
  }

  // If we have an email, print the subject
  fmt.Println("Subject: " + email.Subject)
}

Development

The test suite requires the following environment variables to be set:

export MAILOSAUR_API_KEY=your_api_key
export MAILOSAUR_SERVER=server_id

Run all tests:

go test -v

Contacting us

You can get us at support@mailosaur.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisService

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

func (*AnalysisService) Spam

type Attachment

type Attachment struct {
	Id          string `json:"id,omitempty"`
	ContentType string `json:"contentType"`
	FileName    string `json:"fileName"`
	Content     string `json:"content"`
	ContentId   string `json:"contentId,omitempty"`
	Length      int    `json:"length,omitempty"`
	Url         string `json:"url,omitempty"`
}

type Code

type Code struct {
	Value string `json:"value"`
}

type Device

type Device struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type DeviceCreateOptions

type DeviceCreateOptions struct {
	Name         string `json:"name"`
	SharedSecret string `json:"sharedSecret"`
}

type DeviceListResult

type DeviceListResult struct {
	Items []*Device `json:"items"`
}

type DevicesService

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

func (*DevicesService) Create

func (s *DevicesService) Create(deviceCreateOptions DeviceCreateOptions) (*Device, error)

func (*DevicesService) Delete

func (s *DevicesService) Delete(id string) error

func (*DevicesService) List

func (s *DevicesService) List() (*DeviceListResult, error)

func (*DevicesService) Otp

func (s *DevicesService) Otp(query string) (*OtpResult, error)

type Error

type Error struct {
	Field  string        `json:"field"`
	Detail []ErrorDetail `json:"detail"`
}

type ErrorDetail

type ErrorDetail struct {
	Description string `json:"description"`
}

type ErrorResponse

type ErrorResponse struct {
	Errors []Error `json:"errors"`
}

type FilesService

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

func (*FilesService) GetAttachment

func (s *FilesService) GetAttachment(id string) ([]byte, error)

func (*FilesService) GetEmail

func (s *FilesService) GetEmail(id string) ([]byte, error)

func (*FilesService) GetPreview

func (s *FilesService) GetPreview(id string) ([]byte, error)

type Image

type Image struct {
	Src string `json:"src"`
	Alt string `json:"alt"`
}
type Link struct {
	Href string `json:"href"`
	Text string `json:"text"`
}

type MailosaurClient

type MailosaurClient struct {
	Servers  *ServersService
	Messages *MessagesService
	Analysis *AnalysisService
	Files    *FilesService
	Usage    *UsageService
	Devices  *DevicesService
	Previews *PreviewsService
	// contains filtered or unexported fields
}

func New

func New(apiKey string) *MailosaurClient

func NewWithClient

func NewWithClient(apiKey string, httpClient *http.Client) *MailosaurClient

func (*MailosaurClient) HttpDelete

func (c *MailosaurClient) HttpDelete(path string) error

func (*MailosaurClient) HttpGet

func (c *MailosaurClient) HttpGet(result interface{}, path string) (interface{}, error)

func (*MailosaurClient) HttpPost

func (c *MailosaurClient) HttpPost(result interface{}, path string, body interface{}) (interface{}, error)

func (*MailosaurClient) HttpPut

func (c *MailosaurClient) HttpPut(result interface{}, path string, body interface{}) (interface{}, error)

type Message

type Message struct {
	Id          string            `json:"id"`
	Type        string            `json:"type"`
	From        []*MessageAddress `json:"from"`
	To          []*MessageAddress `json:"to"`
	Cc          []*MessageAddress `json:"cc"`
	Bcc         []*MessageAddress `json:"bcc"`
	Received    time.Time         `json:"received"`
	Subject     string            `json:"subject"`
	Html        *MessageContent   `json:"html"`
	Text        *MessageContent   `json:"text"`
	Attachments []*Attachment     `json:"attachments"`
	Metadata    *Metadata         `json:"metadata"`
	Server      string            `json:"server"`
}

type MessageAddress

type MessageAddress struct {
	Name  string `json:"name"`
	Email string `json:"email"`
	Phone string `json:"phone"`
}

type MessageContent

type MessageContent struct {
	Links  []*Link  `json:"links"`
	Codes  []*Code  `json:"codes"`
	Images []*Image `json:"images"`
	Body   string   `json:"body"`
}

type MessageCreateOptions

type MessageCreateOptions struct {
	To          string       `json:"to"`
	From        string       `json:"from"`
	Send        bool         `json:"send"`
	Subject     string       `json:"subject"`
	Text        string       `json:"text"`
	Html        string       `json:"html"`
	Attachments []Attachment `json:"attachments"`
}

type MessageForwardOptions

type MessageForwardOptions struct {
	To   string `json:"to"`
	Text string `json:"text"`
	Html string `json:"html"`
}

type MessageHeader

type MessageHeader struct {
	Field string `json:"field"`
	Value string `json:"value"`
}

type MessageListParams

type MessageListParams struct {
	Server        string
	ReceivedAfter time.Time
	Page          int
	ItemsPerPage  int
	Dir           string
}

type MessageListResult

type MessageListResult struct {
	Items []*MessageSummary `json:"items"`
}

type MessageReplyOptions

type MessageReplyOptions struct {
	Text        string       `json:"text"`
	Html        string       `json:"html"`
	Attachments []Attachment `json:"attachments"`
}

type MessageSearchParams

type MessageSearchParams struct {
	Server         string
	ReceivedAfter  time.Time
	Page           int
	ItemsPerPage   int
	Timeout        int
	ErrorOnTimeout *bool
	Dir            string
}

type MessageSummary

type MessageSummary struct {
	Id          string            `json:"id"`
	Type        string            `json:"type"`
	Server      string            `json:"server"`
	From        []*MessageAddress `json:"from"`
	To          []*MessageAddress `json:"to"`
	Cc          []*MessageAddress `json:"cc"`
	Bcc         []*MessageAddress `json:"bcc"`
	Received    time.Time         `json:"received"`
	Subject     string            `json:"subject"`
	Summary     string            `json:"summary"`
	Attachments int               `json:"attachments"`
}

type MessagesService

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

func (*MessagesService) Create

func (s *MessagesService) Create(server string, messageCreateOptions *MessageCreateOptions) (*Message, error)

func (*MessagesService) Delete

func (s *MessagesService) Delete(id string) error

func (*MessagesService) DeleteAll

func (s *MessagesService) DeleteAll(server string) error

func (*MessagesService) Forward

func (s *MessagesService) Forward(id string, messageForwardOptions *MessageForwardOptions) (*Message, error)

func (*MessagesService) GeneratePreviews

func (s *MessagesService) GeneratePreviews(id string, options *PreviewRequestOptions) (*PreviewListResult, error)

func (*MessagesService) Get

func (s *MessagesService) Get(params *MessageSearchParams, criteria *SearchCriteria) (*Message, error)

func (*MessagesService) GetById

func (s *MessagesService) GetById(id string) (*Message, error)

func (*MessagesService) List

func (*MessagesService) Reply

func (s *MessagesService) Reply(id string, messageReplyOptions *MessageReplyOptions) (*Message, error)

func (*MessagesService) Search

func (s *MessagesService) Search(params *MessageSearchParams, criteria *SearchCriteria) (*MessageListResult, error)

type Metadata

type Metadata struct {
	Headers  []*MessageHeader  `json:"headers"`
	MailFrom string            `json:"mailFrom"`
	RcptTo   []*MessageAddress `json:"rcptTo"`
	Ehlo     string            `json:"ehlo"`
}

type OtpResult

type OtpResult struct {
	Code    string    `json:"code"`
	Expires time.Time `json:"expires"`
}

type Preview

type Preview struct {
	Id            string `json:"id"`
	EmailClient   string `json:"emailClient"`
	DisableImages bool   `json:"disableImages"`
}

type PreviewEmailClientListResult

type PreviewEmailClientListResult struct {
	Items []*PreviewPreviewEmailClient `json:"items"`
}

type PreviewListResult

type PreviewListResult struct {
	Items []*Preview `json:"items"`
}

type PreviewPreviewEmailClient

type PreviewPreviewEmailClient struct {
	Id               string `json:"id"`
	Name             string `json:"name"`
	PlatformGroup    string `json:"platformGroup"`
	PlatformType     string `json:"platformType"`
	PlatformVersion  string `json:"platformVersion"`
	CanDisableImages bool   `json:"canDisableImages"`
	Status           string `json:"status"`
}

type PreviewRequest

type PreviewRequest struct {
	EmailClient   string `json:"emailClient"`
	DisableImages bool   `json:"disableImages"`
}

type PreviewRequestOptions

type PreviewRequestOptions struct {
	Previews []*PreviewRequest `json:"previews"`
}

type PreviewsService

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

func (*PreviewsService) ListEmailClients

func (s *PreviewsService) ListEmailClients() (*PreviewEmailClientListResult, error)

type SearchCriteria

type SearchCriteria struct {
	SentFrom string `json:"sentFrom"`
	SentTo   string `json:"sentTo"`
	Subject  string `json:"subject"`
	Body     string `json:"body"`
	Match    string `json:"match"`
}

type Server

type Server struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Messages int    `json:"messages"`
}

type ServerCreateOptions

type ServerCreateOptions struct {
	Name string `json:"name"`
}

type ServerListResult

type ServerListResult struct {
	Items []*Server `json:"items"`
}

type ServersService

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

func (*ServersService) Create

func (s *ServersService) Create(serverCreateOptions ServerCreateOptions) (*Server, error)

func (*ServersService) Delete

func (s *ServersService) Delete(id string) error

func (*ServersService) GenerateEmailAddress

func (s *ServersService) GenerateEmailAddress(id string) string

func (*ServersService) Get

func (s *ServersService) Get(id string) (*Server, error)

func (*ServersService) GetPassword

func (s *ServersService) GetPassword(id string) (string, error)

func (*ServersService) List

func (s *ServersService) List() (*ServerListResult, error)

func (*ServersService) Update

func (s *ServersService) Update(id string, server *Server) (*Server, error)

type SpamAnalysisResult

type SpamAnalysisResult struct {
	SpamFilterResults *SpamFilterResults `json:"spamFilterResults"`
	Score             float64            `json:"score"`
}

type SpamAssassinRule

type SpamAssassinRule struct {
	Score       float64 `json:"score"`
	Rule        string  `json:"rule"`
	Description string  `json:"description"`
}

type SpamFilterResults

type SpamFilterResults struct {
	SpamAssassin []*SpamAssassinRule `json:"spamAssassin"`
}

type UsageAccountLimit

type UsageAccountLimit struct {
	Limit   int `json:"limit"`
	Current int `json:"current"`
}

type UsageAccountLimits

type UsageAccountLimits struct {
	Servers *UsageAccountLimit `json:"servers"`
	Users   *UsageAccountLimit `json:"users"`
	Email   *UsageAccountLimit `json:"email"`
	Sms     *UsageAccountLimit `json:"sms"`
}

type UsageService

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

func (*UsageService) Limits

func (s *UsageService) Limits() (*UsageAccountLimits, error)

func (*UsageService) Transactions

func (s *UsageService) Transactions() (*UsageTransactionListResult, error)

type UsageTransaction

type UsageTransaction struct {
	Timestamp time.Time `json:"timestamp"`
	Email     int       `json:"email"`
	Sms       int       `json:"sms"`
}

type UsageTransactionListResult

type UsageTransactionListResult struct {
	Items []*UsageTransaction `json:"items"`
}

Jump to

Keyboard shortcuts

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