smtp Send E-mail
Group send two email , One 163, One QQ
package main
import (
"fmt"
"net/smtp"
"strings"
)
const (
HOST = "smtp.163.com"
SERVER_ADDR = "smtp.163.com:25"
USER = "[email protected]" // E-mail address
PASSWORD = "xxxxx" // The password of the e-mail address
)
type Email struct {
to string "to"
subject string "subject"
msg string "msg"
}
func NewEmail(to, subject, msg string) *Email {
return &Email{to: to, subject: subject, msg: msg}
}
func SendEmail(email *Email) error {
auth := smtp.PlainAuth("", USER, PASSWORD, HOST)
sendTo := strings.Split(email.to, ";")
done := make(chan error, 1024)
go func() {
defer close(done)
for _, v := range sendTo {
str := strings.Replace("From: "+USER+"~To: "+v+"~Subject: "+email.subject+"~~", "~", "\r\n", -1) + email.msg
err := smtp.SendMail(
SERVER_ADDR,
auth,
USER,
[]string{v},
[]byte(str),
)
done <- err
}
}()
for i := 0; i < len(sendTo); i++ {
<-done
}
return nil
}
func main() {
mycontent := "this is go test email"
email := NewEmail("[email protected];[email protected];",
"test golang email", mycontent)
err := SendEmail(email)
fmt.Println(err)
}
Verify email
Send nail profile
Nail alarm settings
Create swarm robots
Address of the interface
Send SMS
Send a normal message
package main
import (
"fmt"
"net/http"
"strings"
)
func main() {
SendDingMsg("zhou","1234")
}
func SendDingMsg(name ,msg string) {
// Request address template
webHook := `https://xxxx`
content := `{"msgtype": "text",
"text": {"content": "` + name+ ":" + msg + `"}
}`
// Create a request
req, err := http.NewRequest("POST", webHook, strings.NewReader(content))
if err != nil {
// handle error
}
client := &http.Client{}
// Set request header
req.Header.Set("Content-Type", "application/json; charset=utf-8")
// Send a request
resp, err := client.Do(req)
// Close request
defer resp.Body.Close()
if err != nil {
// handle error
fmt.Println(err)
}
}