Documentation ¶
Overview ¶
Package libemail provides utilities for composing plaintext or HTML email messages with attachments that can be sent through a typical SMTP server.
Index ¶
- Variables
- type Attachment
- type HTMLEmail
- type Message
- type MessageMock
- func (mmCompile *MessageMock) Compile() (ba1 []byte, err error)
- func (mmCompile *MessageMock) CompileAfterCounter() uint64
- func (mmCompile *MessageMock) CompileBeforeCounter() uint64
- func (m *MessageMock) MinimockCompileDone() bool
- func (m *MessageMock) MinimockCompileInspect()
- func (m *MessageMock) MinimockFinish()
- func (m *MessageMock) MinimockRecipientsDone() bool
- func (m *MessageMock) MinimockRecipientsInspect()
- func (m *MessageMock) MinimockSenderDone() bool
- func (m *MessageMock) MinimockSenderInspect()
- func (m *MessageMock) MinimockWait(timeout mm_time.Duration)
- func (mmRecipients *MessageMock) Recipients() (sa1 []string)
- func (mmRecipients *MessageMock) RecipientsAfterCounter() uint64
- func (mmRecipients *MessageMock) RecipientsBeforeCounter() uint64
- func (mmSender *MessageMock) Sender() (s1 string)
- func (mmSender *MessageMock) SenderAfterCounter() uint64
- func (mmSender *MessageMock) SenderBeforeCounter() uint64
- type MessageMockCompileExpectation
- type MessageMockCompileResults
- type MessageMockRecipientsExpectation
- type MessageMockRecipientsResults
- type MessageMockSenderExpectation
- type MessageMockSenderResults
- type SMTPAuth
- type SMTPAuthMock
- func (m *SMTPAuthMock) MinimockFinish()
- func (m *SMTPAuthMock) MinimockNextDone() bool
- func (m *SMTPAuthMock) MinimockNextInspect()
- func (m *SMTPAuthMock) MinimockStartDone() bool
- func (m *SMTPAuthMock) MinimockStartInspect()
- func (m *SMTPAuthMock) MinimockWait(timeout mm_time.Duration)
- func (mmNext *SMTPAuthMock) Next(fromServer []byte, more bool) (toServer []byte, err error)
- func (mmNext *SMTPAuthMock) NextAfterCounter() uint64
- func (mmNext *SMTPAuthMock) NextBeforeCounter() uint64
- func (mmStart *SMTPAuthMock) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error)
- func (mmStart *SMTPAuthMock) StartAfterCounter() uint64
- func (mmStart *SMTPAuthMock) StartBeforeCounter() uint64
- type SMTPAuthMockNextExpectation
- type SMTPAuthMockNextParams
- type SMTPAuthMockNextResults
- type SMTPAuthMockStartExpectation
- type SMTPAuthMockStartParams
- type SMTPAuthMockStartResults
- type SMTPSender
- type SMTPSenderOptions
- type SendMailFunc
- type Sender
- type SenderMock
- func (m *SenderMock) MinimockFinish()
- func (m *SenderMock) MinimockSendDone() bool
- func (m *SenderMock) MinimockSendInspect()
- func (m *SenderMock) MinimockWait(timeout mm_time.Duration)
- func (mmSend *SenderMock) Send(m1 Message) (err error)
- func (mmSend *SenderMock) SendAfterCounter() uint64
- func (mmSend *SenderMock) SendBeforeCounter() uint64
- type SenderMockSendExpectation
- type SenderMockSendParams
- type SenderMockSendResults
- type TextEmail
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct { Filename string Content []byte Header textproto.MIMEHeader }
Attachment is a representation of an email attachment. There is currently no support for inline attachments.
type HTMLEmail ¶
type HTMLEmail struct { From string To []string ReplyTo string Subject string HtmlBody string TextBody string }
HTMLEmail is a representation of a html encoded email. You can specify the sender, a list of recipients, the subject, and an html encoded body as well as a default utf-8 plain text body.
func (*HTMLEmail) Recipients ¶
type Message ¶
A Message represents something which can be formatted into an RFC-compatible email document, including headers, text, html, and attachments.
type MessageMock ¶
type MessageMock struct { CompileMock mMessageMockCompile RecipientsMock mMessageMockRecipients SenderMock mMessageMockSender // contains filtered or unexported fields }
MessageMock implements Message
func NewMessageMock ¶
func NewMessageMock(t minimock.Tester) *MessageMock
NewMessageMock returns a mock for Message
func (*MessageMock) Compile ¶
func (mmCompile *MessageMock) Compile() (ba1 []byte, err error)
Compile implements Message
func (*MessageMock) CompileAfterCounter ¶
func (mmCompile *MessageMock) CompileAfterCounter() uint64
CompileAfterCounter returns a count of finished MessageMock.Compile invocations
func (*MessageMock) CompileBeforeCounter ¶
func (mmCompile *MessageMock) CompileBeforeCounter() uint64
CompileBeforeCounter returns a count of MessageMock.Compile invocations
func (*MessageMock) MinimockCompileDone ¶
func (m *MessageMock) MinimockCompileDone() bool
MinimockCompileDone returns true if the count of the Compile invocations corresponds the number of defined expectations
func (*MessageMock) MinimockCompileInspect ¶
func (m *MessageMock) MinimockCompileInspect()
MinimockCompileInspect logs each unmet expectation
func (*MessageMock) MinimockFinish ¶
func (m *MessageMock) MinimockFinish()
MinimockFinish checks that all mocked methods have been called the expected number of times
func (*MessageMock) MinimockRecipientsDone ¶
func (m *MessageMock) MinimockRecipientsDone() bool
MinimockRecipientsDone returns true if the count of the Recipients invocations corresponds the number of defined expectations
func (*MessageMock) MinimockRecipientsInspect ¶
func (m *MessageMock) MinimockRecipientsInspect()
MinimockRecipientsInspect logs each unmet expectation
func (*MessageMock) MinimockSenderDone ¶
func (m *MessageMock) MinimockSenderDone() bool
MinimockSenderDone returns true if the count of the Sender invocations corresponds the number of defined expectations
func (*MessageMock) MinimockSenderInspect ¶
func (m *MessageMock) MinimockSenderInspect()
MinimockSenderInspect logs each unmet expectation
func (*MessageMock) MinimockWait ¶
func (m *MessageMock) MinimockWait(timeout mm_time.Duration)
MinimockWait waits for all mocked methods to be called the expected number of times
func (*MessageMock) Recipients ¶
func (mmRecipients *MessageMock) Recipients() (sa1 []string)
Recipients implements Message
func (*MessageMock) RecipientsAfterCounter ¶
func (mmRecipients *MessageMock) RecipientsAfterCounter() uint64
RecipientsAfterCounter returns a count of finished MessageMock.Recipients invocations
func (*MessageMock) RecipientsBeforeCounter ¶
func (mmRecipients *MessageMock) RecipientsBeforeCounter() uint64
RecipientsBeforeCounter returns a count of MessageMock.Recipients invocations
func (*MessageMock) Sender ¶
func (mmSender *MessageMock) Sender() (s1 string)
Sender implements Message
func (*MessageMock) SenderAfterCounter ¶
func (mmSender *MessageMock) SenderAfterCounter() uint64
SenderAfterCounter returns a count of finished MessageMock.Sender invocations
func (*MessageMock) SenderBeforeCounter ¶
func (mmSender *MessageMock) SenderBeforeCounter() uint64
SenderBeforeCounter returns a count of MessageMock.Sender invocations
type MessageMockCompileExpectation ¶
type MessageMockCompileExpectation struct { Counter uint64 // contains filtered or unexported fields }
MessageMockCompileExpectation specifies expectation struct of the Message.Compile
type MessageMockCompileResults ¶
type MessageMockCompileResults struct {
// contains filtered or unexported fields
}
MessageMockCompileResults contains results of the Message.Compile
type MessageMockRecipientsExpectation ¶
type MessageMockRecipientsExpectation struct { Counter uint64 // contains filtered or unexported fields }
MessageMockRecipientsExpectation specifies expectation struct of the Message.Recipients
type MessageMockRecipientsResults ¶
type MessageMockRecipientsResults struct {
// contains filtered or unexported fields
}
MessageMockRecipientsResults contains results of the Message.Recipients
type MessageMockSenderExpectation ¶
type MessageMockSenderExpectation struct { Counter uint64 // contains filtered or unexported fields }
MessageMockSenderExpectation specifies expectation struct of the Message.Sender
type MessageMockSenderResults ¶
type MessageMockSenderResults struct {
// contains filtered or unexported fields
}
MessageMockSenderResults contains results of the Message.Sender
type SMTPAuthMock ¶
type SMTPAuthMock struct { NextMock mSMTPAuthMockNext StartMock mSMTPAuthMockStart // contains filtered or unexported fields }
SMTPAuthMock implements SMTPAuth
func NewSMTPAuthMock ¶
func NewSMTPAuthMock(t minimock.Tester) *SMTPAuthMock
NewSMTPAuthMock returns a mock for SMTPAuth
func (*SMTPAuthMock) MinimockFinish ¶
func (m *SMTPAuthMock) MinimockFinish()
MinimockFinish checks that all mocked methods have been called the expected number of times
func (*SMTPAuthMock) MinimockNextDone ¶
func (m *SMTPAuthMock) MinimockNextDone() bool
MinimockNextDone returns true if the count of the Next invocations corresponds the number of defined expectations
func (*SMTPAuthMock) MinimockNextInspect ¶
func (m *SMTPAuthMock) MinimockNextInspect()
MinimockNextInspect logs each unmet expectation
func (*SMTPAuthMock) MinimockStartDone ¶
func (m *SMTPAuthMock) MinimockStartDone() bool
MinimockStartDone returns true if the count of the Start invocations corresponds the number of defined expectations
func (*SMTPAuthMock) MinimockStartInspect ¶
func (m *SMTPAuthMock) MinimockStartInspect()
MinimockStartInspect logs each unmet expectation
func (*SMTPAuthMock) MinimockWait ¶
func (m *SMTPAuthMock) MinimockWait(timeout mm_time.Duration)
MinimockWait waits for all mocked methods to be called the expected number of times
func (*SMTPAuthMock) Next ¶
func (mmNext *SMTPAuthMock) Next(fromServer []byte, more bool) (toServer []byte, err error)
Next implements SMTPAuth
func (*SMTPAuthMock) NextAfterCounter ¶
func (mmNext *SMTPAuthMock) NextAfterCounter() uint64
NextAfterCounter returns a count of finished SMTPAuthMock.Next invocations
func (*SMTPAuthMock) NextBeforeCounter ¶
func (mmNext *SMTPAuthMock) NextBeforeCounter() uint64
NextBeforeCounter returns a count of SMTPAuthMock.Next invocations
func (*SMTPAuthMock) Start ¶
func (mmStart *SMTPAuthMock) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error)
Start implements SMTPAuth
func (*SMTPAuthMock) StartAfterCounter ¶
func (mmStart *SMTPAuthMock) StartAfterCounter() uint64
StartAfterCounter returns a count of finished SMTPAuthMock.Start invocations
func (*SMTPAuthMock) StartBeforeCounter ¶
func (mmStart *SMTPAuthMock) StartBeforeCounter() uint64
StartBeforeCounter returns a count of SMTPAuthMock.Start invocations
type SMTPAuthMockNextExpectation ¶
type SMTPAuthMockNextExpectation struct { Counter uint64 // contains filtered or unexported fields }
SMTPAuthMockNextExpectation specifies expectation struct of the SMTPAuth.Next
func (*SMTPAuthMockNextExpectation) Then ¶
func (e *SMTPAuthMockNextExpectation) Then(toServer []byte, err error) *SMTPAuthMock
Then sets up SMTPAuth.Next return parameters for the expectation previously defined by the When method
type SMTPAuthMockNextParams ¶
type SMTPAuthMockNextParams struct {
// contains filtered or unexported fields
}
SMTPAuthMockNextParams contains parameters of the SMTPAuth.Next
type SMTPAuthMockNextResults ¶
type SMTPAuthMockNextResults struct {
// contains filtered or unexported fields
}
SMTPAuthMockNextResults contains results of the SMTPAuth.Next
type SMTPAuthMockStartExpectation ¶
type SMTPAuthMockStartExpectation struct { Counter uint64 // contains filtered or unexported fields }
SMTPAuthMockStartExpectation specifies expectation struct of the SMTPAuth.Start
func (*SMTPAuthMockStartExpectation) Then ¶
func (e *SMTPAuthMockStartExpectation) Then(proto string, toServer []byte, err error) *SMTPAuthMock
Then sets up SMTPAuth.Start return parameters for the expectation previously defined by the When method
type SMTPAuthMockStartParams ¶
type SMTPAuthMockStartParams struct {
// contains filtered or unexported fields
}
SMTPAuthMockStartParams contains parameters of the SMTPAuth.Start
type SMTPAuthMockStartResults ¶
type SMTPAuthMockStartResults struct {
// contains filtered or unexported fields
}
SMTPAuthMockStartResults contains results of the SMTPAuth.Start
type SMTPSender ¶
type SMTPSender struct {
// contains filtered or unexported fields
}
SMTPSender is an implementation of Sender that defers to the standard library smtp package for sending a Message.
func (*SMTPSender) Send ¶
func (s *SMTPSender) Send(m Message) error
type SMTPSenderOptions ¶
type SMTPSenderOptions struct { Address string // e.g. localhost:10025 for postfix SendMailFunc SendMailFunc // e.g. smtp.SendMail Auth SMTPAuth // e.g. smtp.Auth, or nil }
SMTPSenderOptions are used to configure an SMTPSender.
type SendMailFunc ¶
SendMailFunc would typically be implemented by simply calling smtp.SendMail but is left as a configurable function for testing purposes.
type Sender ¶
Sender is an interface to be implemented by something which is able to Send a Message.
func NewSMTPSender ¶
func NewSMTPSender(options SMTPSenderOptions) Sender
NewSMTPSender creates an SMTPSender configured with the given options.
The Address and SendMailFunc fields are required, and will cause a panic if left as zero values. The Auth fields can be left nil, if the underlying SMTP server does not have auth enabled.
type SenderMock ¶
type SenderMock struct { SendMock mSenderMockSend // contains filtered or unexported fields }
SenderMock implements Sender
func NewSenderMock ¶
func NewSenderMock(t minimock.Tester) *SenderMock
NewSenderMock returns a mock for Sender
func (*SenderMock) MinimockFinish ¶
func (m *SenderMock) MinimockFinish()
MinimockFinish checks that all mocked methods have been called the expected number of times
func (*SenderMock) MinimockSendDone ¶
func (m *SenderMock) MinimockSendDone() bool
MinimockSendDone returns true if the count of the Send invocations corresponds the number of defined expectations
func (*SenderMock) MinimockSendInspect ¶
func (m *SenderMock) MinimockSendInspect()
MinimockSendInspect logs each unmet expectation
func (*SenderMock) MinimockWait ¶
func (m *SenderMock) MinimockWait(timeout mm_time.Duration)
MinimockWait waits for all mocked methods to be called the expected number of times
func (*SenderMock) Send ¶
func (mmSend *SenderMock) Send(m1 Message) (err error)
Send implements Sender
func (*SenderMock) SendAfterCounter ¶
func (mmSend *SenderMock) SendAfterCounter() uint64
SendAfterCounter returns a count of finished SenderMock.Send invocations
func (*SenderMock) SendBeforeCounter ¶
func (mmSend *SenderMock) SendBeforeCounter() uint64
SendBeforeCounter returns a count of SenderMock.Send invocations
type SenderMockSendExpectation ¶
type SenderMockSendExpectation struct { Counter uint64 // contains filtered or unexported fields }
SenderMockSendExpectation specifies expectation struct of the Sender.Send
func (*SenderMockSendExpectation) Then ¶
func (e *SenderMockSendExpectation) Then(err error) *SenderMock
Then sets up Sender.Send return parameters for the expectation previously defined by the When method
type SenderMockSendParams ¶
type SenderMockSendParams struct {
// contains filtered or unexported fields
}
SenderMockSendParams contains parameters of the Sender.Send
type SenderMockSendResults ¶
type SenderMockSendResults struct {
// contains filtered or unexported fields
}
SenderMockSendResults contains results of the Sender.Send
type TextEmail ¶
type TextEmail struct { From string To []string ReplyTo string Subject string Body string Attachments map[string]*Attachment }
TextEmail is a representation of a plaintext email. You can specify the sender, a list of recipients, the subject, the body, a set of attachments.
func (*TextEmail) Attach ¶
Attach adds creates an Attachment with filename and an io.Reader full of the attachment content.
Attach can be called multiple times to append more than one document.
If two attachments with the same filename are added, an error is returned.
An error is returned if the content of an attachment could not be read.
func (*TextEmail) Compile ¶
Compile returns turns the TextEmail into an RFC compatible set of bytes. If some required field is not present, an error is returned.
func (*TextEmail) Recipients ¶
Recipients returns the complete list of recipients. Since TextEmail currently does not support CC or BCC, this is the same as the "To" field.