mailer

package
v0.0.0-...-9008a76 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeSMTPMsg

func ComposeSMTPMsg(e Email) string

ComposeSMTPMsg builds the content to be sent through an SMTP server

Types

type ConsoleMailer

type ConsoleMailer struct{}

ConsoleMailer implements the Mailer interface to print summaries of emails insted of actually send them.

func NewConsoleMailer

func NewConsoleMailer() *ConsoleMailer

NewConsoleMailer returns a new Mailer that prints emails instead of sending a real email

func (*ConsoleMailer) Send

func (m *ConsoleMailer) Send(e Email) error

Send prints the email to, from and subject fields to console

func (*ConsoleMailer) Sender

func (m *ConsoleMailer) Sender() (string, string)

type Email

type Email struct {
	To      User
	From    User
	Subject string
	HTML    string
	Text    string
}

Email contains all the required information for an email

func (Email) String

func (e Email) String() string

String implements the Stringer interface to print email summary

type LoggerMailer

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

LoggerMailer implements a Mailer interface, wrapping another Mailer, and adding log information to the Send method

func NewLoggerMailer

func NewLoggerMailer(wrapped Mailer, ins *obs.Insighter) *LoggerMailer

NewLoggerMailer wraps a given mailer to add logging information

func (*LoggerMailer) Send

func (m *LoggerMailer) Send(e Email) error

Send sends an email through the wrapped mailer and logs information about the email being sent

func (*LoggerMailer) Sender

func (m *LoggerMailer) Sender() (string, string)

Sender proxies the call to the underlying mailer

type Mailer

type Mailer interface {
	// Send sends an email. Depending on the implementation
	// might require that the e.From.Address matches the one
	// returned from the Sender call.
	Send(e Email) error
	// Sender returns the address and name of the default
	// sender for this maile
	Sender() (string, string)
}

Mailer is the general interface for sending emails

func NewMailtrapMailer

func NewMailtrapMailer(conf MailtrapConfig) (Mailer, error)

NewMailtrapMailer instantiates a new Mailtrap mailer.

type MailgunMailer

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

MailgunMailer implements the Mailer interface to send emails using Mailgun service

func NewMailgunMailer

func NewMailgunMailer(domain string, key string, senderEmail string,
	senderName string, useEUServer bool) (*MailgunMailer, error)

NewMailgunMailer creates a new Mailer to send emails through Mailgun

func (*MailgunMailer) Send

func (m *MailgunMailer) Send(e Email) error

Send sends an email through Mailgun

func (*MailgunMailer) Sender

func (m *MailgunMailer) Sender() (string, string)

Sender returns the default sender address and name

type MailtrapConfig

type MailtrapConfig struct {
	Server   string
	Port     int
	User     string
	Password string
}

MailtrapConfig has the configurations to use the Mailtrap service

type MockMailer

type MockMailer struct {
	SentMails []Email
}

MockMailer implements the Mailer interface, saving emails to be sent in memory (SentMails) instead of actually sending them

func NewMockMailer

func NewMockMailer() *MockMailer

NewMockMailer creates a mailre that stores in memory all sent emails WARNING: Not for production!! Use only for tests

func (*MockMailer) Send

func (m *MockMailer) Send(e Email) error

Send stores the email to be sent in the SentMails field

func (*MockMailer) Sender

func (m *MockMailer) Sender() (string, string)

Sender returns the default sender address and name

type NopMailer

type NopMailer struct{}

NopMailer implements the Mailer interface, but does nothing when Send is called

func NewNopMailer

func NewNopMailer() *NopMailer

NewNopMailer returns a Mailer that does absolutely nothing

func (*NopMailer) Send

func (m *NopMailer) Send(e Email) error

Send makes you believe that is sending an email, but it is not

func (*NopMailer) Sender

func (m *NopMailer) Sender() (string, string)

Sender returns the default sender address and name

type RoundcubeMailer

type RoundcubeMailer struct {
	Server string
	Port   int
}

RoundcubeMailer is an SMTP server for local dev-env environments.

func NewRoundcubeMailer

func NewRoundcubeMailer() *RoundcubeMailer

NewRoundcubeMailer instantiates a new Roundcube mailer.

func (*RoundcubeMailer) Send

func (m *RoundcubeMailer) Send(e Email) error

Send sends an email to Roundcube service.

func (*RoundcubeMailer) Sender

func (m *RoundcubeMailer) Sender() (string, string)

Sender returns the default sender address and name

type SendGridMailer

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

SendGridMailer implements the Mailer interface to send emails using SendGrid service

func NewSendGridMailer

func NewSendGridMailer(key, fromAddress, fromName string) (*SendGridMailer, error)

NewSendGridMailer creates a new Mailer to send emails through SendGrid

func (*SendGridMailer) Send

func (m *SendGridMailer) Send(e Email) error

Send sends an email through SendGrid

func (*SendGridMailer) Sender

func (m *SendGridMailer) Sender() (string, string)

type User

type User struct {
	Name    string
	Address string
}

User is the struct used for defining sender recipient info

func (User) String

func (u User) String() string

String implements the Stringer interface to print user addresses

Jump to

Keyboard shortcuts

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