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
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