Documentation ¶
Index ¶
Constants ¶
const (
SendEmailTask = "mailer.send_email" // SendEmailTask is a task name for sending an email.
)
Predefined task names.
Variables ¶
var ( ErrInvalidTaskPayload = errors.New("invalid task payload") ErrFailedToSendEmail = errors.New("failed to send email") ErrFailedToMarshalPayload = errors.New("failed to marshal payload") ErrFailedToEnqueueTask = errors.New("failed to enqueue task") ErrMissingEmail = errors.New("recipient email address must not be empty") ErrMissingSubject = errors.New("email subject must not be empty") ErrMissingHTMLBody = errors.New("email body cannot be empty") )
Predefined errors.
Functions ¶
func SendEmailHandler ¶ added in v0.2.0
func SendEmailHandler(mail emailAdapter) asyncer.TaskHandler
SendEmailHandler is a function that returns a task handler for sending emails. It takes a mail emailAdapter as a parameter and returns a asyncer.TaskHandler. See details about asyncer module at github.com/dmitrymomot/asyncer. The TaskHandler is responsible for executing the SendEmailTask with the given payload. It sends an email using the provided mail adapter and returns an error if the email fails to send.
Types ¶
type Attachment ¶
type Attachment struct { // Name: attachment name Name string `json:"name,omitempty"` // Content: Base64 encoded attachment data Content string `json:"content,omitempty"` // ContentType: attachment MIME type ContentType string `json:"content_type,omitempty"` // ContentId: populate for inlining images with the images cid ContentID string `json:"content_id,omitempty"` }
Attachment is an optional encoded file to send along with an email
type Enqueuer ¶
type Enqueuer struct {
// contains filtered or unexported fields
}
Enqueuer is a helper struct for enqueuing email tasks. It encapsulates the worker.Enqueuer struct and adds queue methods. See pkg/worker/enqueuer.go.
func NewEnqueuer ¶
func NewEnqueuer(e workerEnqueuer) *Enqueuer
NewEnqueuer creates a new email enqueuer.
func (*Enqueuer) SendEmail ¶
func (e *Enqueuer) SendEmail(ctx context.Context, payload SendEmailPayload) error
SendEmail enqueues a task to send an email. It implements the emailAdapter interface. So, it can be used as a mailer adapter in your application. This function returns an error if the task could not be enqueued.
type SendEmailPayload ¶
type SendEmailPayload struct { // Email is the email address of the recipient. Email string `json:"email,omitempty"` // Subject is the subject of the email. Subject string `json:"subject,omitempty"` // HTMLBody is the HTML body of the email. HTMLBody string `json:"html_body,omitempty"` // Attachments is an optional encoded file to send along with an email (see Attachment). Attachments []Attachment `json:"attachments,omitempty"` }
SendEmailPayload is a payload for SendEmailTask.
func (SendEmailPayload) Validate ¶ added in v0.2.0
func (p SendEmailPayload) Validate() error
Validate validates the SendEmailPayload.