email

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 8 Imported by: 0

README

发邮件

发送邮件,就是这么简单

使用

import (
  "github.com/go-eyas/toolkit/email"
  "github.com/BurntSushi/toml"
)

func ExampleSample() {
	tomlConfig := `
host = "smtp.qq.com"
port = "465"
account = "893521870@qq.com"
password = "haha, wo cai bu gao su ni ne"
name = "unit test"
secure = true
[tpl.a]
bcc = ["Jeason <eyasliu@163.com>"] # 抄送
cc = [] # 抄送人
subject = "Welcome, {{.Name}}" # 主题
text = "Hello, I am {{.Name}}" # 文本
html = "<h1>Hello, I am {{.Name}}</h1>" # html 内容
`
	conf := &Config{}
	toml.Decode(tomlConfig, conf)
	email := New(conf)
	email.SendByTpl("Yuesong Liu <liuyuesongde@163.com>", "a", struct{ Name string }{"Batman"})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name     string
	Account  string
	Password string
	Host     string
	Port     string
	Secure   bool
	TPL      map[string]*TPL
}

type Email

type Email struct {
	SmtpAuth smtp.Auth

	TLS  *tls.Config
	TPLs map[string]*TPL
	// contains filtered or unexported fields
}

func New

func New(conf *Config) *Email

func (*Email) NewEmail

func (e *Email) NewEmail() *email.Email

func (*Email) NewEmailByTpl

func (e *Email) NewEmailByTpl(tplName string, data interface{}) (*email.Email, error)

func (*Email) Send

func (e *Email) Send(addr string, mail *email.Email) error

func (*Email) SendByTpl

func (e *Email) SendByTpl(addr string, tplName string, data interface{}) error

type TPL

type TPL struct {
	Subject string
	From    string
	To      []string
	Bcc     []string
	Cc      []string
	Text    string
	HTML    string
}

Jump to

Keyboard shortcuts

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