Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Send = func(localName, serverAddress string, enableStartTLS, enableImplicitTLS bool, a gosmtp.Auth, from string, to []string, msg []byte) error { host, _, _ := net.SplitHostPort(serverAddress) var c *gosmtp.Client var err error if enableImplicitTLS { // Implicit TLS (SMTPS): wrap connection in TLS before any SMTP command. // Typically used on port 465. var conn *tls.Conn conn, err = tls.Dial("tcp", serverAddress, &tls.Config{ServerName: host}) if err != nil { return err } c, err = gosmtp.NewClient(conn, host) if err != nil { return err } } else { c, err = gosmtp.Dial(serverAddress) if err != nil { return err } } defer func() { _ = c.Close() }() if err = c.Hello(localName); err != nil { return err } if enableStartTLS && !enableImplicitTLS { if ok, _ := c.Extension("STARTTLS"); ok { config := &tls.Config{ServerName: host} if err = c.StartTLS(config); err != nil { return err } } } if a != nil { if ok, _ := c.Extension("AUTH"); !ok { return errors.New("smtp: server doesn't support AUTH") } if err = c.Auth(a); err != nil { return err } } if err = c.Mail(from); err != nil { return err } for _, addr := range to { if err = c.Rcpt(addr); err != nil { return err } } w, err := c.Data() if err != nil { return err } _, err = w.Write(msg) if err != nil { return err } err = w.Close() if err != nil { return err } return c.Quit() }
Functions ¶
func AgnosticAuth ¶
AgnosticAuth returns an Auth that match the correct authentication thanks to gosmtp.ServerInfo
Types ¶
Click to show internal directories.
Click to hide internal directories.