Documentation ¶
Overview ¶
Package send exposes primitives to send emails by responding to CloudEvents.
Index ¶
- func EmailEvent(app *App) func(context.Context, cloudevents.Event) error
- type App
- type AppOption
- func AppWithDomainSender(domain string, sender Sender) AppOption
- func AppWithErrorLogger(logger *log.Logger) AppOption
- func AppWithFileStorage(fileStorage *blob.Bucket) AppOption
- func AppWithFlusher(flusher Flusher) AppOption
- func AppWithInfoLogger(logger *log.Logger) AppOption
- func AppWithLogger(logger *log.Logger) AppOption
- type EventData
- type Flusher
- type MailgunSenderAdapter
- type Message
- type MessageTo
- type NoopSender
- type PubSubMessage
- type PubSubPayload
- type ReadTemplateError
- type Sender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmailEvent ¶
EmailEvent creates a function to send an email by responding to a CloudEvent.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App defines the dependencies the application uses.
type AppOption ¶
type AppOption func(*App)
func AppWithDomainSender ¶
AppWithDomainSender associates a domain with a Sender. Domains will be matched with event supplied [EventData.Sender] i.e. Sender = no-reply@tommymay.dev: domain = tommymay.dev. The matching sender will be used to send the email.
func AppWithErrorLogger ¶
AppWithErrorLogger provides an option to supply an error severity logger.
func AppWithFileStorage ¶
AppWithFileStorage provides an option to specify where email templates should be read from. This can be a local file system, GCS, S3 or any of the other storages supported by the blob package.
func AppWithFlusher ¶
func AppWithInfoLogger ¶
AppWithInfoLogger provides an option to supply an info severity logger.
func AppWithLogger ¶
AppWithLogger is a shortcut for AppWithInfoLogger and AppWithErrorLogger when the logger is the same between the two.
type EventData ¶
type EventData struct { // Sender is who the email is from. Sender string `json:"sender"` // Subject is the email subject line. Subject string `json:"subject"` // Body is the email body and can be HTML. It will be parsed as a [Go HTML template] and bound to the variables // provided by Data. You should not pass both [EventData.Body] and [EventData.Template] at the same // time as they are both meant to represent the email body. // // [Go HTML template]: https://pkg.go.dev/html/template Body string `json:"body"` // To represents who the email should go to and can be provided as an array of strings a string. To MessageTo `json:"to"` // Cc represents who will be carbon copied onto the email and can be provided as an array of string or a string. Cc MessageTo `json:"cc"` // Bcc represents who will be blind carbon copied onto the email and can be provided as an array of string or a // string. Bcc MessageTo `json:"bcc"` // Template is a path to the email template to use as the email [EventData.Body]. It will be parsed as // a [Go HTML template] and bound to the variables provided by Data. You should not pass both // [EventData.Template] and [EventData.Body] at the same time as they are both meant to represent // the email body. // // [Go HTML template]: https://pkg.go.dev/html/template Template string `json:"template"` // Data is an arbitrary map of variables to values that will be used in the [EventData.Template] or // [EventData.Body] using [Go HTML templates]. // // [Go HTML templates]: https://pkg.go.dev/html/template Data map[string]interface{} `json:"data"` }
EventData is this email packages specific event payload data needed to actually send an email.
type Flusher ¶
type Flusher interface {
Flush() error
}
Flusher is used to flush any buffers that may need cleared before exiting the EmailEvent function. This is useful in the context of lambdas like GCP Cloud Functions where it is not reliable that there will be CPU or memory allocated after the EmailEvent function ends.
type MailgunSenderAdapter ¶
type MailgunSenderAdapter struct {
// contains filtered or unexported fields
}
MailgunSenderAdapter allows a mailgun.Mailgun interface to become compatible with the Sender interface.
type Message ¶
type Message struct { Sender string Subject string Body string To []string Cc []string Bcc []string }
Message represents an email.
type MessageTo ¶
type MessageTo []string
MessageTo represents who an email should be sent to.
func (*MessageTo) UnmarshalJSON ¶
type NoopSender ¶
type NoopSender struct{}
NoopSender implements the Sender interface but doesn't actually send any emails which is helpful for testing purposes.
type PubSubMessage ¶
type PubSubMessage struct { Attributes map[string]string `json:"attributes"` MessageId string `json:"messageId"` PublishTime string `json:"publishTime"` // Data is automatically decoded from base64. Data []byte `json:"data"` }
PubSubMessage is the PubsubMessage format when the message comes from Google's Pub/Sub.
type PubSubPayload ¶
type PubSubPayload struct { // Subscription name that this event is associated with. Subscription string `json:"subscription"` Message PubSubMessage `json:"message"` }
PubSubPayload represents GCP pub/sub MessagePublishedData format.
type ReadTemplateError ¶
type ReadTemplateError struct {
// contains filtered or unexported fields
}
ReadTemplateError represents an error that occurs when an email template fails to be retrieved/read.
func (ReadTemplateError) Error ¶
func (readTemplateError ReadTemplateError) Error() string
type Sender ¶
Sender sends an email with the provided Message and returns the ID identifying the request. It should be noted that not all email providers provide any such ID, and therefore it may be an empty string.
func NewMailgunSender ¶
func NewMailgunSender(mailgun mailgun.Mailgun) Sender
NewMailgunSender constructs a MailgunSenderAdapter