go-pkgz / email

Email library to send simple messages
https://go-pkgz.umputun.dev/email/
MIT License
21 stars 6 forks source link
email library

email sending library

Build Status Coverage Status Go Reference

The library is a wrapper around the stdlib net/smtp simplifying email sending. It supports authentication, SSL/TLS, user-specified SMTP servers, content-type, charset, multiple recipients and more.

Usage example:

client := email.NewSender("localhost", email.ContentType("text/html"), email.Auth("user", "pass"))
err := client.Send("<html>some content, foo bar</html>",
    email.Params{From: "me@example.com", To: []string{"to@example.com"}, Subject: "Hello world!",
        Attachments: []string{"/path/to/file1.txt", "/path/to/file2.txt"},
        InlineImages: []string{"/path/to/image1.png", "/path/to/image2.png"},
    })

options

NewSender accepts a number of options to configure the client:

See go docs for Option functions.

Options should be passed to NewSender after the mandatory first (host) parameter.

sending email

To send email user need to create a sender first and then use Send method. The method accepts two parameters:

See go docs for Send function.

technical details

limitations

This library is not intended to be used for sending a lot of massive emails with low latency requirements. The intended use case is sending simple messages, like alerts, notification and so on. For example, sending alerts from a monitoring system, or for authentication-related emails, i.e. "password reset email", "verification email", etc.