Documentation
¶
Overview ¶
Package email provides email sending functionality using SMTP.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotConfigured is returned when SMTP is not configured. ErrNotConfigured = errors.New("email: SMTP not configured") // ErrInvalidRecipient is returned when the recipient email is invalid. ErrInvalidRecipient = errors.New("email: invalid recipient email") // ErrSendFailed is returned when email sending fails. ErrSendFailed = errors.New("email: failed to send email") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string
Port int
User string
Password string
From string
FromName string
TLS bool
SkipVerify bool
Timeout time.Duration
}
Config holds SMTP configuration.
type LoggingSender ¶
type LoggingSender struct {
// contains filtered or unexported fields
}
LoggingSender wraps a sender and logs all email operations.
func NewLoggingSender ¶
func NewLoggingSender(sender Sender, logger Logger) *LoggingSender
NewLoggingSender creates a new logging sender.
func (*LoggingSender) IsConfigured ¶
func (s *LoggingSender) IsConfigured() bool
IsConfigured returns true if the underlying sender is configured.
func (*LoggingSender) Send ¶
func (s *LoggingSender) Send(ctx context.Context, msg *Message) error
Send logs and sends the email.
func (*LoggingSender) SendTemplate ¶
func (s *LoggingSender) SendTemplate(ctx context.Context, to string, template Template, data any) error
SendTemplate logs and sends a templated email.
type Message ¶
type Message struct {
To []string
Subject string
Body string
IsHTML bool
ReplyTo string
Headers map[string]string
}
Message represents an email message.
type NoOpSender ¶
type NoOpSender struct{}
NoOpSender is a sender that does nothing (for development/testing).
func (*NoOpSender) IsConfigured ¶
func (s *NoOpSender) IsConfigured() bool
IsConfigured always returns true for no-op sender.
func (*NoOpSender) Send ¶
func (s *NoOpSender) Send(_ context.Context, _ *Message) error
Send does nothing and returns nil.
func (*NoOpSender) SendTemplate ¶
SendTemplate does nothing and returns nil.
type PasswordChangedData ¶
type PasswordChangedData struct {
UserName string
Email string
ChangedAt string
IPAddress string
AppName string
SupportURL string
}
PasswordChangedData holds data for the password changed notification.
type PasswordResetData ¶
type PasswordResetData struct {
UserName string
Email string
ResetURL string
ExpiresIn string
AppName string
IPAddress string
RequestedAt string
}
PasswordResetData holds data for the password reset template.
type SMTPSender ¶
type SMTPSender struct {
// contains filtered or unexported fields
}
SMTPSender implements Sender using SMTP.
func NewSMTPSender ¶
func NewSMTPSender(cfg Config) *SMTPSender
NewSMTPSender creates a new SMTP sender.
func (*SMTPSender) IsConfigured ¶
func (s *SMTPSender) IsConfigured() bool
IsConfigured returns true if SMTP is properly configured.
func (*SMTPSender) Send ¶
func (s *SMTPSender) Send(ctx context.Context, msg *Message) error
Send sends an email message.
func (*SMTPSender) SendTemplate ¶
func (s *SMTPSender) SendTemplate(ctx context.Context, to string, template Template, data any) error
SendTemplate sends an email using a predefined template.
type Sender ¶
type Sender interface {
Send(ctx context.Context, msg *Message) error
SendTemplate(ctx context.Context, to string, template Template, data any) error
IsConfigured() bool
}
Sender defines the interface for sending emails.
type TeamInvitationData ¶
type TeamInvitationData struct {
InviterName string
TeamName string
InvitationURL string
ExpiresIn string
AppName string
}
TeamInvitationData holds data for the team invitation template.
type Template ¶
type Template string
Template represents a predefined email template type.
const ( // TemplateVerifyEmail is the email verification template. TemplateVerifyEmail Template = "verify_email" // TemplatePasswordReset is the password reset template. TemplatePasswordReset Template = "password_reset" // TemplatePasswordChanged is the password changed notification template. TemplatePasswordChanged Template = "password_changed" // TemplateWelcome is the welcome email template. TemplateWelcome Template = "welcome" // TemplateTeamInvitation is the team invitation template. TemplateTeamInvitation Template = "team_invitation" )
type TemplateEngine ¶
type TemplateEngine struct {
// contains filtered or unexported fields
}
TemplateEngine handles email template rendering.
func NewTemplateEngine ¶
func NewTemplateEngine() *TemplateEngine
NewTemplateEngine creates a new template engine with all predefined templates.