package mail

import "github.com/gobuffalo/buffalo/mail"

Index

Types

type Attachment

type Attachment struct {
	Name        string
	Reader      io.Reader
	ContentType string
	Embedded    bool
}

Attachment are files added into a email message

type BatchSender

type BatchSender interface {
	Sender
	SendBatch(messages ...Message) (errorsByMessages []error, generalError error)
}

BatchSender interface for sending batch or single mail

type Body

type Body struct {
	Content     string
	ContentType string
}

Body represents one of the bodies in the Message could be main or alternative

type Message

type Message struct {
	Context     context.Context
	From        string
	To          []string
	CC          []string
	Bcc         []string
	Subject     string
	Headers     map[string]string
	Data        render.Data
	Bodies      []Body
	Attachments []Attachment
	// contains filtered or unexported fields
}

Message represents an Email message

func New

func New(c buffalo.Context) Message

New builds a new message with the current buffalo.Context

func NewFromData

func NewFromData(data render.Data) Message

NewFromData builds a new message with raw template data given

func NewMessage

func NewMessage() Message

NewMessage builds a new message.

func (*Message) AddAttachment

func (m *Message) AddAttachment(name, contentType string, r io.Reader) error

AddAttachment adds the attachment to the list of attachments the Message has.

func (*Message) AddBodies

func (m *Message) AddBodies(data render.Data, renderers ...render.Renderer) error

AddBodies Allows to add multiple bodies to the message, it returns errors that could happen in the rendering.

func (*Message) AddBody

func (m *Message) AddBody(r render.Renderer, data render.Data) error

AddBody the message by receiving a renderer and rendering data, first message will be used as the main message Body rest of them will be passed as alternative bodies on the email message

func (*Message) AddEmbedded

func (m *Message) AddEmbedded(name string, r io.Reader) error

AddEmbedded adds the attachment to the list of attachments the Message has and uses inline instead of attachement property.

func (*Message) SetHeader

func (m *Message) SetHeader(field, value string)

SetHeader sets the heder field and value for the message

type SMTPSender

type SMTPSender struct {
	Dialer *gomail.Dialer
}

SMTPSender allows to send Emails by connecting to a SMTP server.

func NewSMTPSender

func NewSMTPSender(host string, port string, user string, password string) (SMTPSender, error)

NewSMTPSender builds a SMTP mail based in passed config.

func (SMTPSender) Send

func (sm SMTPSender) Send(message Message) error

Send a message using SMTP configuration or returns an error if something goes wrong.

func (SMTPSender) SendBatch

func (sm SMTPSender) SendBatch(messages ...Message) (errorsByMessages []error, generalError error)

SendBatch of message with one connection, returns general error or errors specific for each message

type Sender

type Sender interface {
	Send(Message) error
}

Sender interface for any upcoming mailers.

Source Files

attachment.go body.go mail.go message.go sender.go smtp_sender.go

Directories

PathSynopsis
mail/internal
Version
v1.1.2 (latest)
Published
May 17, 2025
Platform
js/wasm
Imports
9 packages
Last checked
1 week ago

Tools for package owners.