mail

package
v0.0.0-...-8b7da69 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: Apache-2.0 Imports: 5 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFilters

func AddFilters(c context.Context, filts ...Filter) context.Context

AddFilters adds RawInterface filters to the context.

func Send

func Send(c context.Context, msg *Message) error

Send sends an e-mail message.

func SendToAdmins

func SendToAdmins(c context.Context, msg *Message) error

SendToAdmins sends an e-mail message to application administrators.

func Set

Set sets the mail service in this context. Useful for testing with a quick mock. This is just a shorthand SetFactory invocation to set a factory which always returns the same object.

func SetFactory

func SetFactory(c context.Context, f Factory) context.Context

SetFactory sets the function to produce mail.RawInterface instances, as returned by the Get method.

Types

type Attachment

type Attachment struct {
	// Name must be set to a valid file name.
	Name      string
	Data      []byte
	ContentID string
}

Attachment is a mimic of https://godoc.org/google.golang.org/appengine/mail#Attachment

It's provided here for convenience, and is compile-time checked to be identical.

type Factory

type Factory func(context.Context) RawInterface

Factory is the function signature for factory methods compatible with SetFactory.

type Filter

Filter is the function signature for a filter mail implementation. It gets the current mail implementation, and returns a new mail implementation backed by the one passed in.

type Message

type Message struct {
	Sender      string
	ReplyTo     string
	To, Cc, Bcc []string
	Subject     string
	Body        string
	HTMLBody    string
	Attachments []Attachment
	Headers     net_mail.Header
}

Message is a mimic of https://godoc.org/google.golang.org/appengine/mail#Message

It's provided here for convenience, and is init-time checked to be identical (not statically because []Attachement prevents static casting).

func (*Message) Copy

func (m *Message) Copy() *Message

Copy returns a duplicate Message

func (*Message) ToSDKMessage

func (m *Message) ToSDKMessage() *mail.Message

ToSDKMessage returns a copy of this Message that's compatible with the native SDK's Message type. It only needs to be used by implementations (like "impl/prod") which need an SDK compatible object

type RawInterface

type RawInterface interface {
	Send(msg *Message) error
	SendToAdmins(msg *Message) error

	GetTestable() Testable
}

RawInterface is the interface for all of the mail methods.

These replicate the methods found here: https://godoc.org/google.golang.org/appengine/mail

func Raw

Raw pulls the raw mail service implementation from context or nil if it wasn't set.

type TestMessage

type TestMessage struct {
	Message

	// MIMETypes is guaranteed to be the same length as the attachments in the
	// Message, and will be populated with the derived MIME types for the
	// attachments.
	MIMETypes []string
}

TestMessage is the message struct which will be returned from SentMessages.

It augments the Message struct by also including the derived MIMEType for any attachments.

func (*TestMessage) Copy

func (t *TestMessage) Copy() *TestMessage

Copy duplicates this TestMessage.

type Testable

type Testable interface {
	// Sets the list of admin emails. By default, testing implementations should
	// use ["admin@example.com"].
	SetAdminEmails(emails ...string)

	// SentMessages returns a copy of all messages which were successfully sent
	// via the mail API.
	SentMessages() []*TestMessage

	// Reset clears the SentMessages queue.
	Reset()
}

Testable is the interface for mail service implementations which are able to be tested (like impl/memory).

func GetTestable

func GetTestable(c context.Context) Testable

GetTestable returns a testable extension interface, or nil if one is not available.

Jump to

Keyboard shortcuts

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