Documentation ¶
Overview ¶
Package smtp provides supports for sending emails
Package smtp provides supports for sending emails
Index ¶
- Constants
- func Activate(c *dataprovider.SMTPConfigs)
- func IsEnabled() bool
- func ReloadProviderConf()
- func RenderPasswordExpirationTemplate(buf *bytes.Buffer, data any) error
- func RenderPasswordResetTemplate(buf *bytes.Buffer, data any) error
- func SendEmail(to, bcc []string, subject, body string, contentType EmailContentType, ...) error
- type Config
- type EmailContentType
- type OAuth2Config
Constants ¶
const ( OAuth2ProviderGoogle = iota OAuth2ProviderMicrosoft )
Supported OAuth2 providers
Variables ¶
This section is empty.
Functions ¶
func Activate ¶ added in v2.5.0
func Activate(c *dataprovider.SMTPConfigs)
Activate sets the specified config as active
func ReloadProviderConf ¶ added in v2.5.0
func ReloadProviderConf()
ReloadProviderConf reloads the configuration from the provider and apply it if different from the active one
func RenderPasswordExpirationTemplate ¶ added in v2.5.0
RenderPasswordExpirationTemplate executes the password expiration template
func RenderPasswordResetTemplate ¶
RenderPasswordResetTemplate executes the password reset template
Types ¶
type Config ¶
type Config struct { // Location of SMTP email server. Leavy empty to disable email sending capabilities Host string `json:"host" mapstructure:"host"` // Port of SMTP email server Port int `json:"port" mapstructure:"port"` // From address, for example "SFTPGo <sftpgo@example.com>". // Many SMTP servers reject emails without a `From` header so, if not set, // SFTPGo will try to use the username as fallback, this may or may not be appropriate From string `json:"from" mapstructure:"from"` // SMTP username User string `json:"user" mapstructure:"user"` // SMTP password. Leaving both username and password empty the SMTP authentication // will be disabled Password string `json:"password" mapstructure:"password"` // 0 Plain // 1 Login // 2 CRAM-MD5 // 3 OAuth2 AuthType int `json:"auth_type" mapstructure:"auth_type"` // 0 no encryption // 1 TLS // 2 start TLS Encryption int `json:"encryption" mapstructure:"encryption"` // Domain to use for HELO command, if empty localhost will be used Domain string `json:"domain" mapstructure:"domain"` // Path to the email templates. This can be an absolute path or a path relative to the config dir. // Templates are searched within a subdirectory named "email" in the specified path TemplatesPath string `json:"templates_path" mapstructure:"templates_path"` // Set to 1 to enable debug logs Debug int `json:"debug" mapstructure:"debug"` // OAuth2 related settings OAuth2 OAuth2Config `json:"oauth2" mapstructure:"oauth2"` }
Config defines the SMTP configuration to use to send emails
func (*Config) Initialize ¶
Initialize initialized and validates the SMTP configuration
type EmailContentType ¶
type EmailContentType int
EmailContentType defines the support content types for email body
const ( EmailContentTypeTextPlain EmailContentType = iota EmailContentTypeTextHTML )
Supported email body content type
type OAuth2Config ¶ added in v2.5.2
type OAuth2Config struct { Provider int `json:"provider" mapstructure:"provider"` // Tenant for Microsoft provider, if empty "common" is used Tenant string `json:"tenant" mapstructure:"tenant"` // ClientID is the application's ID ClientID string `json:"client_id" mapstructure:"client_id"` // ClientSecret is the application's secret ClientSecret string `json:"client_secret" mapstructure:"client_secret"` // Token to use to get/renew access tokens RefreshToken string `json:"refresh_token" mapstructure:"refresh_token"` // contains filtered or unexported fields }
OAuth2Config defines OAuth2 settings
func (*OAuth2Config) GetOAuth2 ¶ added in v2.5.2
func (c *OAuth2Config) GetOAuth2() *oauth2.Config
GetOAuth2 returns the oauth2 configuration for the provided parameters.
func (*OAuth2Config) Validate ¶ added in v2.5.2
func (c *OAuth2Config) Validate() error
Validate validates and initializes the configuration