smtp

package
v2.0.0-...-83f77b2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package smtp provides supports for sending emails

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if an SMTP server is configured

func RenderPasswordResetTemplate

func RenderPasswordResetTemplate(buf *bytes.Buffer, data any) error

RenderPasswordResetTemplate executes the password reset template

func SendEmail

func SendEmail(to []string, subject, body string, contentType EmailContentType, attachments ...mail.File) error

SendEmail tries to send an email using the specified parameters.

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
	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"`
}

Config defines the SMTP configuration to use to send emails

func (*Config) Initialize

func (c *Config) Initialize(configDir string) error

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

Jump to

Keyboard shortcuts

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