email

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: MIT Imports: 9 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

Types

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