go-simple-mail
包提供了一種簡便的方式來處理和發送郵件。這個包支持保持活動連接、TLS和SSL加密協議,非常適合批量SMTP郵件發送需求。
1、安裝Go-Simple-Mail包
go get -u github.com/xhit/go-simple-mail/v2
2、配置SMTP服務器連接
go-simple-mail
包支持多種SMTP服務器連接的配置,包括TLS和SSL。
package mainimport (mail "github.com/xhit/go-simple-mail/v2""log""time"
)func main() {server := mail.NewSMTPClient()server.Host = "smtp.example.com"server.Port = 587 // 或者465(SSL)server.Username = "your-email@example.com"server.Password = "your-email-password"server.Encryption = mail.EncryptionTLS // 可以用 mail.EncryptionNone, mail.EncryptionSSL, mail.EncryptionTLSserver.KeepAlive = trueserver.ConnectTimeout = 10 * time.Secondserver.SendTimeout = 10 * time.Seconds