mail

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: MIT Imports: 3 Imported by: 0

README

Gomail

Documentation

Introduction

Gomail is a simple and efficient package to send emails. It is well tested and documented.

Gomail can only send emails using an SMTP server. But the API is flexible and it is easy to implement other methods for sending emails using a local Postfix, an API, etc.

It is versioned using gopkg.in so I promise there will never be backward incompatible changes within each version.

It requires Go 1.2 or newer. With Go 1.5, no external dependencies are used.

Features

Gomail supports:

  • Attachments
  • Embedded images
  • HTML and text templates
  • Automatic encoding of special characters
  • SSL and TLS
  • Sending multiple emails with the same SMTP connection
  • Support use proxy dialer

Documentation

https://godoc.org/github.com/lfhy/mail

Download

go install github.com/lfhy/mail@latest

Examples

See the examples in the documentation.

FAQ

x509: certificate signed by unknown authority

If you get this error it means the certificate used by the SMTP server is not considered valid by the client running Gomail. As a quick workaround you can bypass the verification of the server's certificate chain and host name by using SetTLSConfig:

    package main

    import (
    	"crypto/tls"

    	"github.com/lfhy/mail"
    )

    func main() {
    	d := mail.New(mail.SetTLSConfig(&tls.Config{InsecureSkipVerify: true}))
        // or use mail.SetSkipTLS(true) to skip TLS
        // d := mail.New(mail.SetSkipTLS(true))
        // Send emails using d.
    }

Note, however, that this is insecure and should not be used in production.

Contribute

Contributions are more than welcome! See CONTRIBUTING.md for more info.

Change log

See CHANGELOG.md.

License

MIT

Contact

You can ask questions on the Gomail thread in the Go mailing-list.

Documentation

Overview

Example
package main

import (
	"github.com/lfhy/mail"
	"golang.org/x/net/proxy"
)

func main() {
	mailer := mail.New(
		mail.SetHost("smtp.example.com"),
		mail.SetPort(587),
		mail.SetUser("[email protected]"),
		mail.SetPassword("password"),
		mail.SetFrom("user"),
		mail.SetSkipTLS(true),
		mail.SetDialer(proxy.Direct),
	)
	mailer.SendMail("title", "test mail", "[email protected]")
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MailConfig

type MailConfig struct {
	User     string // Send mail user: [email protected]
	Password string // Send mail password: password
	Host     string // Send mail host: stmp.test.com
	Port     int    // Send mail port: 465
	From     string // Send mail show from: testuser

	Subject   string       // Send mail subject: test mail
	Content   string       // Send mail content: test mail content
	Dialer    proxy.Dialer // Send mail dialer
	TLSConfig *tls.Config
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *MailConfig

func (*MailConfig) Send

func (m *MailConfig) Send(mailTo ...string) error

func (*MailConfig) SendMail

func (m *MailConfig) SendMail(subject, content string, mailTo ...string) error

type Option added in v1.0.1

type Option func(*MailConfig)

func SetContent added in v1.0.1

func SetContent(content string) Option

func SetDialer added in v1.0.1

func SetDialer(dialer proxy.Dialer) Option

func SetFrom added in v1.0.1

func SetFrom(from string) Option

func SetHost added in v1.0.1

func SetHost(host string) Option

func SetPassword added in v1.0.1

func SetPassword(password string) Option

func SetPort added in v1.0.1

func SetPort(port int) Option

func SetSkipTLS added in v1.0.1

func SetSkipTLS(skip bool) Option

func SetSubject added in v1.0.1

func SetSubject(subject string) Option

func SetTLSConfig added in v1.0.1

func SetTLSConfig(config *tls.Config) Option

func SetUser added in v1.0.1

func SetUser(user string) Option

Directories

Path Synopsis
Package gomail provides a simple interface to compose emails and to mail them efficiently.
Package gomail provides a simple interface to compose emails and to mail them efficiently.

Jump to

Keyboard shortcuts

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