gomailer

package module
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 14 Imported by: 0

README

Build Status

gomailer

wrapper golang email with automatic reconnection

Intentions & Features

  • Based on https://gopkg.in/gomail.v2
  • Auto reconnection broken pipe from SMTP server
  • Avoid too many login attempts because of redial & close
  • Unit-testable/ mock-able with gomock provided
  • Support Golang context
  • Support Postmark

Usage

Example is provided in example/ folder/ package

c, _ := gomailer.NewClient(gomailer.Gomail, &gomailer.Config{
  Port:     587,
  Host:     "smtp.gmail.com",
  Email:    "user@email.com",
  Password: "user_password",
})
  
err := c.Send(&gomailer.Message{
  Body:   "body" + t.String(),
  Title:  "test",
  SendTo: []string{"receiver@mail.com"},
})

Offline Contributors

erosaru

Documentation

Overview

Package gomailer is a generated GoMock package.

Index

Constants

View Source
const (
	Gomail = Implementation(iota)
	Postmark
)

Variables

View Source
var ErrClosed = errors.New("connection has been closed")

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename string
	Byte     []byte
}

type Client

type Client interface {
	// Send will send email
	Send(msg *Message) error
	// SendContext provide context to send function
	SendContext(ctx context.Context, msg *Message) error
	// SendAsync sends email asynchronously ignoring future error
	SendAsync(msg *Message) error
	// Close permanently close client connection
	Close() error
}

func NewClient

func NewClient(impl Implementation, emailConfig *Config) (Client, error)

New email return email handler struct

type Config

type Config struct {
	Host string
	Port int

	// FromEmail configures the global senderPool's email
	FromEmail string

	Username string
	Password string

	// Postmark Settings
	ServerToken  string
	AccountToken string
}

type Implementation

type Implementation int

type Message

type Message struct {
	// From overrides global senderPool's email
	From        string
	Attachments []*Attachment
	SendTo      []string
	CC          []string
	BCC         []string
	Title       string
	Body        string
	// ContentType defaults to "text/html" if not set
	ContentType string
}

type MockClient

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

MockClient is a mock of Client interface

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance

func (*MockClient) Close

func (m *MockClient) Close() error

Close mocks base method

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockClient) Send

func (m *MockClient) Send(msg *Message) error

Send mocks base method

func (*MockClient) SendAsync added in v0.6.0

func (m *MockClient) SendAsync(msg *Message) error

SendAsync mocks base method

func (*MockClient) SendContext added in v0.2.0

func (m *MockClient) SendContext(ctx context.Context, msg *Message) error

SendContext mocks base method

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient

func (*MockClientMockRecorder) Close

func (mr *MockClientMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close

func (*MockClientMockRecorder) Send

func (mr *MockClientMockRecorder) Send(msg interface{}) *gomock.Call

Send indicates an expected call of Send

func (*MockClientMockRecorder) SendAsync added in v0.6.0

func (mr *MockClientMockRecorder) SendAsync(msg interface{}) *gomock.Call

SendAsync indicates an expected call of SendAsync

func (*MockClientMockRecorder) SendContext added in v0.2.0

func (mr *MockClientMockRecorder) SendContext(ctx, msg interface{}) *gomock.Call

SendContext indicates an expected call of SendContext

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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