Skip to content

net.smtp

fn new_client #

fn new_client(config Config) !&Client

new_client returns a new SMTP client and connects to it

fn BodyType.from #

fn BodyType.from[W](input W) !BodyType

from returns the BodyType value of an integer or of a field name, or an error if there is none.

enum BodyType #

enum BodyType {
	text
	html
}

struct Attachment #

struct Attachment {
pub:
	cid      string
	filename string
	bytes    []u8
}

Attachment is a MIME attachment. CR and LF are removed from its filename and cid. Filename quotes and backslashes are escaped when writing the MIME parameter.

struct Client #

struct Client {
	Config
mut:
	conn     net.TcpConn
	ssl_conn &ssl.SSLConn = unsafe { nil }
	reader   ?&io.BufferedReader
pub mut:
	is_open   bool
	encrypted bool
}

fn (Client) reconnect #

fn (mut c Client) reconnect() !

reconnect reconnects to the SMTP server if the connection was closed

fn (Client) send #

fn (mut c Client) send(config Mail) !

send sends an email to every mailbox in config.to, config.cc, and config.bcc. Recipient lists are semicolon-separated; Bcc mailboxes are envelope-only and are not exposed in the message headers.

fn (Client) quit #

fn (mut c Client) quit() !

quit closes the connection to the server

struct Config #

struct Config {
pub:
	server                 string
	port                   int = 25
	username               string
	password               string
	from                   string
	ssl                    bool
	starttls               bool
	timeout                time.Duration
	validate               bool = true
	verify                 string
	in_memory_verification bool
	allow_insecure_auth    bool
}

Config stores the settings used to connect a new SMTP client. TLS certificates are validated by default and require verify to name a PEM CA bundle; set in_memory_verification when it contains PEM data. Credentials are refused without TLS unless allow_insecure_auth enables cleartext auth. Setting validate to false disables certificate chain and hostname checks.

struct Mail #

struct Mail {
pub:
	from        string
	to          string
	cc          string
	bcc         string
	date        time.Time = time.now()
	subject     string
	body_type   BodyType
	body        string
	attachments []Attachment
	html        Message
	text        Message
	boundary    string
}

Mail stores the message headers and MIME payload sent by Client.send. to, cc, and bcc are semicolon-separated mailbox lists. Client.send uses all three lists as SMTP envelope recipients, writes non-empty To and Cc headers, and omits Bcc from the message data.

struct Message #

struct Message {
pub:
	body        string
	attachments []Attachment
}

Message stores one body variant and optional attachments for a Mail.