Ejemplo n.º 1
0
func sendMail(mo *MailObject) {
	mcfg := g.GetConfig().Mail
	msg := gomail.NewMessage()
	// from
	msg.SetAddressHeader("From", mcfg.MailServerAccount, mo.FromUser)
	// receivers
	for i, to := range mo.Receivers {
		if i == 0 {
			msg.SetHeader("To", to)
		} else {
			msg.AddHeader("To", to)
		}
	}
	// subject
	msg.SetHeader("Subject", mo.Subject)
	// content
	msg.SetBody("text/plain", mo.Content)

	// statistics
	proc.MailSendCnt.Incr()

	m := gomail.NewMailer(mcfg.MailServerHost, mcfg.MailServerAccount, mcfg.MailServerPasswd, mcfg.MailServerPort)
	if err := m.Send(msg); err != nil {
		// statistics
		proc.MailSendErrCnt.Incr()
		log.Println(err, ", mailObject:", mo)
	} else {
		// statistics
		proc.MailSendOkCnt.Incr()
	}
}
Ejemplo n.º 2
0
// try pushing one mail into sender queue, maybe failed
func AddMail(r []string, subject string, content string, from ...string) bool {
	mcfg := g.GetConfig().Mail
	fromUserName := mcfg.FromUser
	if len(from) == 1 {
		fromUserName = from[0]
	}

	nm := NewMailObject(r, subject, content, fromUserName)
	return mailqueue.PushFront(nm)
}
Ejemplo n.º 3
0
func startHttpServer() {
	if !g.GetConfig().Http.Enable {
		return
	}

	addr := g.GetConfig().Http.Listen
	if addr == "" {
		return
	}

	addRoutes()
	s := &http.Server{
		Addr:           addr,
		MaxHeaderBytes: 1 << 30,
	}

	log.Println("http.startHttpServer ok, listening", addr)
	log.Fatalln(s.ListenAndServe())
}
Ejemplo n.º 4
0
func Start() {
	sendsema = nsema.NewSemaphore(g.GetConfig().Mail.SendConcurrent)
	mailqueue = nlist.NewSafeListLimited(g.GetConfig().Mail.MaxQueueSize)
	go startSender()
}