package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"qfw/util/mail"
	"os"
	qu "qfw/util"
)
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 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(xlsx_name)
	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)
}