luci: Index | Files

package mail

import ""


Package Files

context.go interface.go message.go testable.go

func AddFilters Uses

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

AddFilters adds RawInterface filters to the context.

func Send Uses

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

Send sends an e-mail message.

func SendToAdmins Uses

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

SendToAdmins sends an e-mail message to application administrators.

func Set Uses

func Set(c context.Context, u RawInterface) context.Context

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 Uses

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

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

type Attachment Uses

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

Attachment is a mimic of

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

type Factory Uses

type Factory func(context.Context) RawInterface

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

type Filter Uses

type Filter func(context.Context, RawInterface) RawInterface

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 Uses

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

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

func (*Message) Copy Uses

func (m *Message) Copy() *Message

Copy returns a duplicate Message

func (*Message) ToSDKMessage Uses

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 Uses

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:

func Raw Uses

func Raw(c context.Context) RawInterface

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

type TestMessage Uses

type TestMessage struct {

    // 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 Uses

func (t *TestMessage) Copy() *TestMessage

Copy duplicates this TestMessage.

type Testable Uses

type Testable interface {
    // Sets the list of admin emails. By default, testing implementations should
    // use [""].
    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.

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

func GetTestable Uses

func GetTestable(c context.Context) Testable

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

Package mail imports 5 packages (graph) and is imported by 8 packages. Updated 2021-01-26. Refresh now. Tools for package owners.