config

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config handles multi-account email configuration.

Index

Constants

View Source
const (
	DefaultIMAPRateLimitRPM = 60
	DefaultSMTPRateLimitRPH = 100
	DefaultIMAPTimeoutMS    = 30000
	DefaultSMTPTimeoutMS    = 30000

	DefaultMaxAttachmentSizeMB      = 18
	DefaultMaxTotalAttachmentSizeMB = 18
	DefaultMaxDownloadSizeMB        = 25
	DefaultPoolCloseTimeoutMS       = 5000
)

Variables

View Source
var (
	ErrNoConfig           = errors.New("EMAIL_ACCOUNTS or EMAIL_CONFIG_FILE must be set")
	ErrNoAccounts         = errors.New("no accounts configured")
	ErrOAuthMissingClient = errors.New("oauth2 requires oauth_client_id")
	ErrUnknownAuthMethod  = errors.New("unknown auth_method")
)

Sentinel errors for configuration loading and validation.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID                 string `json:"id"`
	Email              string `json:"email"`
	IMAPHost           string `json:"imap_host"`
	IMAPPort           int    `json:"imap_port"`
	SMTPHost           string `json:"smtp_host"`
	SMTPPort           int    `json:"smtp_port"`
	Username           string `json:"username"`
	Password           string `json:"password"`
	UseStartTLS        *bool  `json:"use_starttls,omitempty"`         // nil = auto-detect based on port
	InsecureSkipVerify bool   `json:"insecure_skip_verify,omitempty"` // skip TLS cert verify
	AuthMethod         string `json:"auth_method,omitempty"`          // "password" (default) or "oauth2"
	OAuthClientID      string `json:"oauth_client_id,omitempty"`      // OAuth2 client ID
	OAuthClientSecret  string `json:"oauth_client_secret,omitempty"`  // OAuth2 client secret
	OAuthTokenFile     string `json:"oauth_token_file,omitempty"`     // override token file path
}

Account represents a single email account configuration.

func (*Account) IMAPUseTLS

func (a *Account) IMAPUseTLS() bool

IMAPUseTLS returns true if IMAP should use implicit TLS (port 993). Returns false if STARTTLS should be used (port 143 or explicit config).

func (*Account) SMTPUseTLS

func (a *Account) SMTPUseTLS() bool

SMTPUseTLS returns true if SMTP should use implicit TLS (port 465). Returns false if STARTTLS should be used (port 587 or explicit config).

type Config

type Config struct {
	Accounts                 []Account
	DefaultAccount           string
	IMAPRateLimitRPM         int
	SMTPRateLimitRPH         int
	IMAPTimeoutMS            int
	SMTPTimeoutMS            int
	MaxAttachmentSizeMB      int
	MaxTotalAttachmentSizeMB int
	MaxDownloadSizeMB        int
	PoolCloseTimeoutMS       int
	Debug                    bool
}

Config holds the full email server configuration.

func LoadFromEnv

func LoadFromEnv() (*Config, error)

LoadFromEnv loads configuration from environment variables.

func (*Config) GetAccount

func (c *Config) GetAccount(id string) (*Account, error)

GetAccount returns an account by ID, or the default account if id is empty.

type ProviderResult

type ProviderResult struct {
	IMAPHost string
	IMAPPort int
	SMTPHost string
	SMTPPort int
}

ProviderResult holds the detected IMAP/SMTP settings for a provider.

func DetectProvider

func DetectProvider(email string) *ProviderResult

DetectProvider returns IMAP/SMTP settings for well-known email providers. Returns nil if the domain is not recognized.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL