email

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

邮箱报警

如使用自建邮件系统请设置 skipVerify 为 true 以避免证书校验错误

Example

  • SendEmailByTls
func SendTLS() {
	address := "smtp.163.com"
	from := "...@163.com"
	password := "..."
	// if use qq
	// https://service.mail.qq.com/cgi-bin/help?subtype=1&&no=1001256&&id=28
	address = "smtp.qq.com"
	from = "...@qq.com"
	password = "..."

	to := "to1@email.com"
	subject:= ""
	body:=""

	tls := true
	anonymous := false
	// 如使用自建邮件系统请设置 skipVerify 为 true 以避免证书校验错误
	skipVerify = true
	port := 465
	s := NewSMTP(address, from, password, from, html, tls, anonymous, skipVerify, port)
	err := s.Send([]string{to}, subject, body)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}
}

  • SendEmail
func Send() {
	address := "smtp.163.com"
	from := "...@163.com"
	password := "..."

	to := "to1@email.com"
	subject:= ""
	body:=""
	
	tls := true
	anonymous := false
	// 如使用自建邮件系统请设置 skipVerify 为 true 以避免证书校验错误
	skipVerify = true
	port := 25

	s := NewSMTP(address, from, password, from, plain, tls, anonymous, skipVerify, port)
	s.Send([]string{tos}, subject, body)
}
  • SendEmailAnonyMous
func SendAnonyMous() {
	address := "smtp.custom.com"
	from := "noreply@custom.com"
		
	to := "to1@email.com"
	subject:= ""
	body:=""
	
	tls := true
	anonymous := true
	// 如使用自建邮件系统请设置 skipVerify 为 true 以避免证书校验错误
	skipVerify = true
	port := 25

	s := NewSMTP(address, "", "", from, plain, tls, anonymous, skipVerify, 25)
	s.Send([]string{tos}, subject, body)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSMTP

func NewSMTP(smtphost string, port int, username, password, from string, tls, anonymous, skipVerify bool) notify.Sender

NewSMTP return a tls Smtp

func SendMailTest

func SendMailTest()

Types

type MailboxConf

type MailboxConf struct {
	// 邮件标题
	Title string
	// 邮件内容
	Body string
	// 邮件附件
	Attach []string
	// 收件人列表
	RecipientList []string
	// 发件人账号
	Sender string
	// 发件人密码,QQ邮箱这里配置授权码
	Password string
	From     string
	// SMTP 服务器地址, QQ邮箱是smtp.qq.com
	SMTPAddr string
	// SMTP端口 QQ邮箱是25
	SMTPPort int
	Tls      bool
}

MailboxConf 邮箱配置

func NewMail

func NewMail(username, password, SMTPAddr, from string, SMTPPort int, tls bool) MailboxConf

func (MailboxConf) Send

func (mailConf MailboxConf) Send(title, body string, RecipientList, AttachList []string) error

type SMTP

type SMTP struct {
	SMTPHost   string
	Port       int
	Username   string
	Password   string
	From       string
	TLS        bool
	Anonymous  bool
	SkipVerify bool
}

SMTP is email conf

func (*SMTP) Send

func (s *SMTP) Send(tos []string, title, content string) error

Send send email to user

Jump to

Keyboard shortcuts

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