email

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 16 Imported by: 0

README

email

参考github.com/jordan-wright/email和smtp协议写的一个可以发送邮件的工具,主要以学习为目的。其发送普通邮件示例:

    import (
        "net/smtp"
        "github.com/quixote-liu/email"
    )

    func main() {
        e := email.Email{
            From:     "your_email@mail.com",
            To:       []string{"target_email@qq.com"},
            Subject:  "This is Subject",
            Addr:     "smtp.example.com:25",
        }

        if err := e.AttachFile("./filename.txt"); err != nil {
        	log.Fatal(err)
        }

        auth := smtp.PlainAuth("", "your_email@mail.com", "your_password", "smtp.example.com")
        message := []byte("hello, world")

        err := e.SetAuth(auth).WriteText(message).Send()
        if err != nil {
            log.Fatal(err)
        }

        // reset email message, include attchments.
        e.Reset()
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Email

type Email struct {
	From     string
	Sender   string
	ReplyTo  []string
	To       []string
	CC       []string
	BCC      []string
	Subject  string
	Comments string

	// with host and port.
	Addr string
	// contains filtered or unexported fields
}

func (*Email) AttachFile

func (e *Email) AttachFile(filename string) error

func (*Email) Reset

func (e *Email) Reset()

func (*Email) Send

func (e *Email) Send() error

func (*Email) SetAuth

func (e *Email) SetAuth(a smtp.Auth) *Email

func (*Email) WriteHTML

func (e *Email) WriteHTML(html []byte) *Email

func (*Email) WriteText

func (e *Email) WriteText(text []byte) *Email

Jump to

Keyboard shortcuts

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