Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterSchemas(r *settings.Registry)
- type Address
- type Attachment
- type Config
- type Mailer
- type MailgunConfig
- type MailgunMailer
- type Message
- type NoopMailer
- type SESConfig
- type SESMailer
- type SESQuota
- type SMTPConfig
- type SMTPMailer
- type SendGridConfig
- type SendGridMailer
- type SettingsProvider
Constants ¶
const ( SettingEnabled = "mailer.enabled" SettingMode = "mailer.mode" SettingProvider = "mailer.provider" SettingFromEmail = "mailer.from_email" SettingFromName = "mailer.from_name" SettingSMTPHost = "mailer.smtp_host" SettingSMTPPort = "mailer.smtp_port" SettingSMTPUsername = "mailer.smtp_username" SettingSMTPPassword = "mailer.smtp_password" SettingSMTPTLS = "mailer.smtp_tls" SettingSMTPStartTLS = "mailer.smtp_starttls" SettingSMTPInsecureSkip = "mailer.smtp_insecure_skip_verify" SettingMailgunAPIKey = "mailer.mailgun_api_key" SettingMailgunDomain = "mailer.mailgun_domain" SettingMailgunBaseURL = "mailer.mailgun_base_url" SettingSendGridAPIKey = "mailer.sendgrid_api_key" SettingSESRegion = "mailer.ses_region" SettingSESAccessKeyID = "mailer.ses_access_key_id" SettingSESSecretAccessKey = "mailer.ses_secret_access_key" SettingSESConfigSetName = "mailer.ses_configuration_set_name" )
const ( ModeDisabled = "disabled" ModeDryRun = "dry_run" ModeActive = "active" )
Variables ¶
var Schemas = []settings.Schema{ { Key: SettingEnabled, Type: settings.Bool, Default: "false", Label: "Enable Mailer", Description: "Enable mail delivery provider", }, { Key: SettingMode, Type: settings.Enum, Default: ModeDisabled, Label: "Mailer Runtime Mode", Description: "Controls mail delivery execution mode", Options: []string{ModeDisabled, ModeDryRun, ModeActive}, Labels: []string{"Disabled", "Dry Run", "Active"}, }, { Key: SettingProvider, Type: settings.Enum, Default: "smtp", Label: "Mailer Provider", Description: "Mail delivery provider", Options: []string{"smtp", "mailgun", "sendgrid", "ses"}, Labels: []string{"SMTP", "Mailgun", "SendGrid", "AWS SES"}, }, {Key: SettingFromEmail, Type: settings.String, Default: "noreply@localhost", Label: "From Email", MaxLength: 255}, {Key: SettingFromName, Type: settings.String, Label: "From Name", MaxLength: 255}, {Key: SettingSMTPHost, Type: settings.String, Label: "SMTP Host", MaxLength: 255}, {Key: SettingSMTPPort, Type: settings.Int, Default: "587", Label: "SMTP Port"}, {Key: SettingSMTPUsername, Type: settings.String, Label: "SMTP Username", MaxLength: 255}, {Key: SettingSMTPPassword, Type: settings.String, Label: "SMTP Password", Secret: true, MaxLength: 255}, {Key: SettingSMTPTLS, Type: settings.Bool, Default: "false", Label: "SMTP TLS"}, {Key: SettingSMTPStartTLS, Type: settings.Bool, Default: "false", Label: "SMTP STARTTLS"}, {Key: SettingSMTPInsecureSkip, Type: settings.Bool, Default: "false", Label: "SMTP Insecure Skip Verify"}, {Key: SettingMailgunAPIKey, Type: settings.String, Label: "Mailgun API Key", Secret: true, MaxLength: 255}, {Key: SettingMailgunDomain, Type: settings.String, Label: "Mailgun Domain", MaxLength: 255}, {Key: SettingMailgunBaseURL, Type: settings.String, Label: "Mailgun Base URL", MaxLength: 255}, {Key: SettingSendGridAPIKey, Type: settings.String, Label: "SendGrid API Key", Secret: true, MaxLength: 255}, {Key: SettingSESRegion, Type: settings.String, Default: "us-east-1", Label: "SES Region", MaxLength: 64}, {Key: SettingSESAccessKeyID, Type: settings.String, Label: "SES Access Key ID", Secret: true, MaxLength: 255}, {Key: SettingSESSecretAccessKey, Type: settings.String, Label: "SES Secret Access Key", Secret: true, MaxLength: 255}, {Key: SettingSESConfigSetName, Type: settings.String, Label: "SES Configuration Set Name", MaxLength: 255}, }
Functions ¶
func RegisterSchemas ¶
RegisterSchemas registers mailer settings schemas.
Types ¶
type Attachment ¶
Attachment represents an email attachment.
type Config ¶
type Config struct {
// DefaultFrom replaces an empty Message.From.Email before active-provider
// validation. Send does not change the caller's message.
DefaultFrom Address
Provider string
}
Config holds common mailer configuration.
type Mailer ¶
Mailer defines the interface for sending emails.
func NewWithSettings ¶
NewWithSettings resolves mailer from static config and dynamic settings overrides.
type MailgunConfig ¶
MailgunConfig holds Mailgun-specific configuration.
type MailgunMailer ¶
type MailgunMailer struct {
// contains filtered or unexported fields
}
MailgunMailer sends emails via Mailgun API.
func NewMailgunMailer ¶
func NewMailgunMailer(cfg MailgunConfig) *MailgunMailer
NewMailgunMailer creates a new Mailgun mailer.
type Message ¶
type Message struct {
From Address
To []Address
CC []Address
BCC []Address
ReplyTo *Address
Subject string
Text string
HTML string
Attachments []Attachment
// Headers holds unfolded custom fields. Names use printable ASCII except
// spaces and colons; values must not contain CR or LF.
Headers map[string]string
}
Message represents an email message.
func (*Message) AllRecipients ¶
AllRecipients returns all recipients (To + CC + BCC).
func (*Message) HasAttachments ¶
HasAttachments returns true if the message has attachments.
func (*Message) IsMultipart ¶
IsMultipart returns true if the message has both text and HTML parts.
type NoopMailer ¶
type NoopMailer struct {
// contains filtered or unexported fields
}
NoopMailer is a mailer that logs messages instead of sending them.
func NewNoopMailer ¶
func NewNoopMailer(log log.Logger) *NoopMailer
NewNoopMailer creates a new noop mailer.
type SESConfig ¶
type SESConfig struct {
Config
Region string
AccessKeyID string
SecretAccessKey string
ConfigurationSetName string
}
SESConfig holds AWS SES-specific configuration.
type SESMailer ¶
type SESMailer struct {
// contains filtered or unexported fields
}
SESMailer sends emails via AWS Simple Email Service.
func NewSESMailer ¶
NewSESMailer creates a new AWS SES mailer.
func (*SESMailer) GetSendQuota ¶
GetSendQuota returns the current sending quota.
type SESQuota ¶
SESQuota represents SES sending quota.
func (*SESQuota) RemainingQuota ¶
RemainingQuota returns the remaining emails that can be sent in 24h.
type SMTPConfig ¶
type SMTPConfig struct {
Config
Host string
Port int
Username string
Password string
// TLS requires implicit TLS and takes precedence over StartTLS.
TLS bool
// StartTLS requires an advertised, successful upgrade when TLS is false.
// When both flags are false, an advertised upgrade remains opportunistic.
StartTLS bool
// InsecureSkipVerify disables certificate verification for both TLS paths.
InsecureSkipVerify bool
}
SMTPConfig holds SMTP-specific configuration.
type SMTPMailer ¶
type SMTPMailer struct {
// contains filtered or unexported fields
}
SMTPMailer sends emails via SMTP.
func NewSMTPMailer ¶
func NewSMTPMailer(cfg SMTPConfig) *SMTPMailer
NewSMTPMailer creates a new SMTP mailer.
type SendGridConfig ¶
SendGridConfig holds SendGrid-specific configuration.
type SendGridMailer ¶
type SendGridMailer struct {
// contains filtered or unexported fields
}
SendGridMailer sends emails via SendGrid API.
func NewSendGridMailer ¶
func NewSendGridMailer(cfg SendGridConfig) *SendGridMailer
NewSendGridMailer creates a new SendGrid mailer.
type SettingsProvider ¶
type SettingsProvider interface {
GetString(ctx context.Context, key string) (string, error)
GetInt(ctx context.Context, key string) (int, error)
GetBool(ctx context.Context, key string) (bool, error)
}
SettingsProvider provides dynamic settings used to resolve mailer runtime configuration.