123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package main
- import (
- "fmt"
- "io/ioutil"
- "log"
- "net/http"
- "os"
- qu "qfw/util"
- "qfw/util/mail"
- )
- var tomail string
- var api string
- var from,to,cc, smtpHost,user,pwd string
- var smtpPort int
- //api模式 二选一皆可
- func sendErrMailApi(title,body string) {
- jkmail, _ := sysconfig["jkmail"].(map[string]interface{})
- if jkmail != nil {
- tomail, _ = jkmail["to"].(string)
- api, _ = jkmail["api"].(string)
- }
- log.Println(tomail,api)
- res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", api, tomail, title, body))
- if err == nil {
- defer res.Body.Close()
- read, err := ioutil.ReadAll(res.Body)
- log.Println("邮件发送成功:", string(read), err)
- }else {
- log.Println("邮件发送失败:", err)
- }
- }
- func sendErrMailSmtp(title,body,xlsxName string) {
- smtpMail, _ := sysconfig["smtpMail"].(map[string]interface{})
- if smtpMail != nil {
- from, _ = smtpMail["from"].(string)
- to, _ = smtpMail["to"].(string)
- cc, _ = smtpMail["cc"].(string)
- smtpHost, _ = smtpMail["smtpHost"].(string)
- smtpPort= qu.IntAll(smtpMail["smtpPort"])
- user, _ = smtpMail["user"].(string)
- pwd, _ = smtpMail["pwd"].(string)
- }
- f, _ := os.Open(xlsxName)
- b, err := ioutil.ReadAll(f)
- if err != nil {
- fmt.Println("err:",err)
- return
- }
- ok := mail.GSendMail_Bq(from, to, cc, cc, title, body, f.Name(), b, &mail.GmailAuth{
- SmtpHost: smtpHost,
- SmtpPort: smtpPort,
- User: user,
- Pwd: pwd,
- })
- fmt.Println(ok)
- if !ok {//邮件发送异常
- sendWarningSmtp("邮件附件发送异常","请检查......")
- }
- }
- func sendWarningSmtp(title,body string) {
- smtpMail, _ := sysconfig["smtpMail"].(map[string]interface{})
- if smtpMail != nil {
- from, _ = smtpMail["from"].(string)
- to, _ = smtpMail["to"].(string)
- cc, _ = smtpMail["cc"].(string)
- smtpHost, _ = smtpMail["smtpHost"].(string)
- smtpPort= qu.IntAll(smtpMail["smtpPort"])
- user, _ = smtpMail["user"].(string)
- pwd, _ = smtpMail["pwd"].(string)
- }
- ok := mail.GSendMail(from, from, from, from, title, body, "", "", &mail.GmailAuth{
- SmtpHost: smtpHost,
- SmtpPort: smtpPort,
- User: user,
- Pwd: pwd,
- })
- fmt.Println(ok)
- }
|