Documentation
¶
Overview ¶
Package goat provides email delivery with templating capabilities.
go-at simplifies sending emails from Go applications with built-in templating and support for multiple delivery providers (SendGrid and Brevo).
Basic usage:
service := goat.NewSendgridService("api-key", "Your Name", "you@company.com")
restore := goat.SetSenderService(service)
defer restore()
template := goat.Template{
Name: "welcome",
ContentRaw: "Hello {{.Name}}!",
Data: map[string]string{"Name": "John"},
}
content, _ := template.Render()
err := goat.Send("user@example.com", "Welcome", content, content)
To use Brevo instead of SendGrid, create the service with NewBrevoService:
service := goat.NewBrevoService("api-key", "Your Name", "you@company.com")
For more details, see README.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEmailValid ¶
func Send ¶
func Send(message *EmailMessage) error
Send directly exposes the current sender service Send function.
func SetSenderService ¶
func SetSenderService(service SenderService) func()
SetSenderService affect a new repository to the global service singleton
Types ¶
type BrevoClient ¶ added in v1.1.0
type BrevoClient interface {
SendTransacEmail(ctx context.Context, sendSmtpEmail brevo.SendSmtpEmail) (brevo.CreateSmtpEmail, *http.Response, error)
}
BrevoClient is an interface for sending emails
type BrevoService ¶ added in v1.1.0
type BrevoService struct {
// contains filtered or unexported fields
}
BrevoService implements the SenderService interface using Brevo
func (*BrevoService) Send ¶ added in v1.1.0
func (s *BrevoService) Send(message *EmailMessage) error
Send sends an email using Brevo
type EmailMessage ¶ added in v1.2.0
type EmailMessage struct {
To string
Subject string
PlainTextContent string
HTMLContent string
ReplyTo *ReplyTo
Headers map[string]string
}
EmailMessage represents an email to be sent. Build one with NewEmailMessage and chain With* methods for optional fields.
func NewEmailMessage ¶ added in v1.2.0
func NewEmailMessage(to, subject, plainTextContent, htmlContent string) *EmailMessage
NewEmailMessage creates a new EmailMessage with the required fields.
func (*EmailMessage) WithHeader ¶ added in v1.2.0
func (m *EmailMessage) WithHeader(key, value string) *EmailMessage
WithHeader adds a single custom header and returns the message for chaining.
func (*EmailMessage) WithHeaders ¶ added in v1.2.0
func (m *EmailMessage) WithHeaders(headers map[string]string) *EmailMessage
WithHeaders sets all custom headers at once and returns the message for chaining.
func (*EmailMessage) WithReplyTo ¶ added in v1.2.0
func (m *EmailMessage) WithReplyTo(name, address string) *EmailMessage
WithReplyTo sets the reply-to address and returns the message for chaining.
type SenderService ¶
type SenderService interface {
Send(message *EmailMessage) error
}
SenderService defines the interface for handling emails
func GetSenderService ¶
func GetSenderService() SenderService
GetSenderService is used to access the global service singleton
func NewBrevoService ¶ added in v1.1.0
func NewBrevoService(apiKey, senderName, senderEmail string) SenderService
NewBrevoService returns a new instance of BrevoService
func NewSendgridService ¶
func NewSendgridService(apiKey, senderName, senderEmail string) SenderService
NewSendgridService returns a new instance of SendgridService
type SendgridClient ¶
type SendgridClient interface {
Send(email *mail.SGMailV3) (*rest.Response, error)
SendWithContext(ctx context.Context, email *mail.SGMailV3) (*rest.Response, error)
}
SendgridClient is an interface for sending emails
type SendgridService ¶
type SendgridService struct {
// contains filtered or unexported fields
}
SendgridService implements the SenderService interface using SendGrid
func (*SendgridService) Send ¶
func (s *SendgridService) Send(message *EmailMessage) error
Send sends an email using SendGrid