mailer

package module
v0.0.0-...-721ee8d Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 24 Imported by: 0

README

mailer

Build Status | codecov | Go Report Card | GoDoc

A simple and fast SMTP email client.

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

Dependecy Management

Dep

Project dependencies are managed using Dep. Read more about Dep.

  • Install dependencies: dep ensure
  • Update dependencies: dep ensure -update
Go
go get github.com/joaosoft/mailer

Usage

This examples are available in the project at mailer/examples

Code
import "github.com/joaosoft/mailer"

// create a client
client := mailer.NewMailer()

dir, _ := os.Getwd()

image, err := mailer.ReadFile(dir+"/examples/attachments/mail.png", nil)
failed, err := client.SendMessage().
    From("João Ribeiro", "joaosoft@gmail.com").
    To("joao.ribeiro@foursource.pt", "invalid", "joao.ribeiro@foursource.pt").
    Cc("joao.ribeiro@foursource.pt", "joao.ribeiro@foursource.pt").
    Bcc("joao.ribeiro@foursource.pt", "joao.ribeiro@foursource.pt").
    Header("aFrom", "fake@mail.pt").
    Subject("This is a test subject").
    Body(mailer.ContentTypeTextPlain, "Hello, you got an email!\n\n").
    Date(time.Now()).
    Attachment(image, true, "image_file_1.png").
    Execute()


if err != nil {
    fmt.Printf(err.Error())
}

if len(failed) > 0 {
    fmt.Printf("\n\nFailed addresses: %+v", failed)
}

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

View Source
const (
	EncodingBase64 Encoding = "base64"

	ContentTypeJSON          ContentType = "application/json"
	ContentTypeJavaScript    ContentType = "application/javascript"
	ContentTypeXML           ContentType = "application/xml"
	ContentTypeTextXML       ContentType = "text/xml"
	ContentTypeForm          ContentType = "application/x-www-form-urlencoded"
	ContentTypeProtobuf      ContentType = "application/protobuf"
	ContentTypeMsgpack       ContentType = "application/msgpack"
	ContentTypeTextHTML      ContentType = "text/html"
	ContentTypeTextPlain     ContentType = "text/plain"
	ContentTypeMultipartForm ContentType = "multipart/form-data"
	ContentTypeOctetStream   ContentType = "application/octet-stream"

	MimeVersion1 MimeVersion = "1.0"
	CharsetUTF8  Charset     = "UTF-8"
)

Variables

This section is empty.

Functions

func Exists

func Exists(file string) bool

func GetEnv

func GetEnv() string

func GetMimeType

func GetMimeType(fileName string) (mimeType string)

func RandomBoundary

func RandomBoundary() string

func ReadFile

func ReadFile(file string, obj interface{}) ([]byte, error)

func ReadFileLines

func ReadFileLines(file string) ([]string, error)

func SendMail

func SendMail(addr string, a Auth, from string, to []string, msg []byte) ([]string, error)

func WriteFile

func WriteFile(file string, obj interface{}) error

Types

type AppConfig

type AppConfig struct {
	Mailer *MailerConfig `json:"mailer"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type Attachment

type Attachment struct {
	FileName       string
	Content        []byte
	Inline         bool
	ContentType    string
	Encoding       Encoding
	EncodedContent string
}

type Auth

type Auth interface {
	Start(server *ServerInfo) (proto string, toServer []byte, err error)
	Next(fromServer []byte, more bool) (toServer []byte, err error)
}

func CRAMMD5Auth

func CRAMMD5Auth(username, secret string) Auth

func PlainAuth

func PlainAuth(identity, username, password, host string) Auth

type Charset

type Charset string

type Client

type Client struct {
	Text *textproto.Conn
	// contains filtered or unexported fields
}

func Dial

func Dial(addr string) (*Client, error)

func NewClient

func NewClient(conn net.Conn, host string) (*Client, error)

func (*Client) Auth

func (c *Client) Auth(a Auth) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) Data

func (c *Client) Data() (io.WriteCloser, error)

func (*Client) Extension

func (c *Client) Extension(ext string) (bool, string)

func (*Client) Hello

func (c *Client) Hello(localName string) error

func (*Client) Mail

func (c *Client) Mail(from string) error

func (*Client) Quit

func (c *Client) Quit() error

func (*Client) Rcpt

func (c *Client) Rcpt(to string) error

func (*Client) Reset

func (c *Client) Reset() error

func (*Client) StartTLS

func (c *Client) StartTLS(config *tls.Config) error

func (*Client) TLSConnectionState

func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)

func (*Client) Verify

func (c *Client) Verify(addr string) error

type ContentType

type ContentType string

type Encoding

type Encoding string

type Mailer

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

func NewMailer

func NewMailer(options ...MailerOption) *Mailer

NewMailer ...

func (*Mailer) Reconfigure

func (mailer *Mailer) Reconfigure(options ...MailerOption)

Reconfigure ...

func (*Mailer) SendMessage

func (e *Mailer) SendMessage() *SendMessageService

type MailerConfig

type MailerConfig struct {
	Log struct {
		Level string `json:"level"`
	} `json:"log"`
	Host     string `json:"host"`
	Port     string `json:"port"`
	Identity string `json:"identity"`
	Username string `json:"username"`
	Password string `json:"password"`
}

MailerConfig ...

type MailerOption

type MailerOption func(client *Mailer)

MailerOption ...

func WithConfiguration

func WithConfiguration(config *MailerConfig) MailerOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) MailerOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) MailerOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) MailerOption

WithManager ...

type Message

type Message struct {
	MimeVersion         MimeVersion
	Headers             map[string]string
	FromName            string
	FromAddr            string
	ToAddrs             []string
	CcAddrs             []string
	BccAddrs            []string
	Date                string
	ReplyToAddr         string
	Subject             string
	BoundaryMixed       string
	BoundaryAlternative string
	ContentType         ContentType
	Charset             Charset
	Body                string
	Attachments         []*Attachment
	// contains filtered or unexported fields
}

type MimeVersion

type MimeVersion string

type SendMessageService

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

func NewSendMessageService

func NewSendMessageService(e *Mailer) *SendMessageService

func (*SendMessageService) Attachment

func (e *SendMessageService) Attachment(content []byte, inline bool, fileName string) *SendMessageService

func (*SendMessageService) Bcc

func (*SendMessageService) Body

func (e *SendMessageService) Body(contentType ContentType, body string) *SendMessageService

func (*SendMessageService) Cc

func (*SendMessageService) Date

func (*SendMessageService) Execute

func (e *SendMessageService) Execute() ([]string, error)

func (*SendMessageService) From

func (e *SendMessageService) From(name, address string) *SendMessageService

func (*SendMessageService) Header

func (e *SendMessageService) Header(key string, value string) *SendMessageService

func (*SendMessageService) Subject

func (e *SendMessageService) Subject(subject string) *SendMessageService

func (*SendMessageService) Template

func (e *SendMessageService) Template(path, name string, reload bool) *SendMessageService

func (*SendMessageService) To

type ServerInfo

type ServerInfo struct {
	Name string
	TLS  bool
	Auth []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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