email

package
v6.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package email simple email sender

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mail

type Mail interface {
	// Login login to SMTP server
	Login(username, password string)
	// Send send email
	Send(frAddr, toAddr, frName, toName, subject, content string, optfs ...SendOption) (err error)
}

Mail is a simple email sender

Example
sender := NewMail("smtp_host", 53)
if err := sender.Send(
	"fromAddr",
	"toAddr",
	"frName",
	"toName",
	"Title",
	"Content",
); err != nil {
	log.Shared.Error("try to send email got error", zap.Error(err))
}

type MailT

type MailT struct {
	// contains filtered or unexported fields
}

MailT easy way to send basic email

func NewMail

func NewMail(host string, port int) *MailT

NewMail create Mail with SMTP host and port

func (*MailT) BuildMessage

func (m *MailT) BuildMessage(msg string) string

BuildMessage implement

func (*MailT) Login

func (m *MailT) Login(username, password string)

Login login to SMTP server

func (*MailT) Send

func (m *MailT) Send(frAddr, toAddr, frName, toName, subject, content string, optfs ...SendOption) (err error)

Send send email

type SendOption

type SendOption func(*mailSendOpt)

SendOption is a function to set option for Mail.Send

func WithEmailRequireTLS added in v6.3.0

func WithEmailRequireTLS(tlsConfig ...*tls.Config) SendOption

WithEmailRequireTLS enforces an encrypted SMTP connection and refuses to fall back to plaintext.

Security: by default delivery uses gomail's opportunistic STARTTLS. A network attacker can defeat that by stripping the STARTTLS capability from the server's EHLO response, causing credentials and message content to be transmitted in cleartext (a STARTTLS-stripping downgrade attack). With this option set, Send requires encryption: for the conventional implicit-TLS port 465 it dials directly over TLS, and for any other port it requires the server to advertise STARTTLS and aborts WITHOUT sending if it does not.

An optional *tls.Config may be supplied; when nil a config using the SMTP host as ServerName and a TLS 1.2 minimum is used.

If WithMailSendDialer is also provided, the explicitly supplied dialer takes precedence and this option has no effect.

func WithMailSendDialer

func WithMailSendDialer(dialerFact func(host string, port int, username, passwd string) Sender) SendOption

WithMailSendDialer set gomail.Dialer

type Sender

type Sender interface {
	DialAndSend(m ...*gomail.Message) error
}

Sender create gomail.Dialer

Jump to

Keyboard shortcuts

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