Beispiel #1
0
func (dm *Daemon) workerSendFunc() error {
	for {
		select {
		case m, ok := <-dm.msgChan:
			if !ok {
				dm.closed = true
				return nil
			}

			if err := gomail.Send(dm.sendFunc, m); err != nil {
				log.Error("mail.daemon.Start.Send", "err", err, "message", m)
			}
		}
	}
}
Beispiel #2
0
func (dm *Daemon) workerSendFunc() error {
	for {
		select {
		case m, ok := <-dm.msgChan:
			if !ok {
				dm.closed = true
				return nil
			}

			if err := gomail.Send(dm.sendFunc, m); err != nil {
				// dont terminate this for loop
				PkgLog.Info("mail.daemon.Start.Send", "err", err, "message", m)
			}
		}
	}
}
Beispiel #3
0
func (dm *Daemon) workerDial() error {
	var s gomail.SendCloser
	var err error
	open := false
	for {
		select {
		case m, ok := <-dm.msgChan:
			if !ok {
				dm.closed = true
				return nil
			}
			if !open {
				if s, err = dm.dialer.Dial(); err != nil {
					PkgLog.Info("mail.daemon.workerDial.Dial", "err", err, "message", m)
					return err
				}
				open = true
			}
			if err := gomail.Send(s, m); err != nil {
				PkgLog.Info("mail.daemon.workerDial.Send", "err", err, "message", m)
			}
		// Close the connection to the SMTP server if no email was sent in
		// the last n seconds.
		case <-time.After(dm.SmtpTimeout):
			//			if open && dm.lastIDchanged {
			//				// once the configuration changed and there is an open connection
			//				// we have to close it and reconnect with the new SMTP login data.
			//				if err := s.Close(); err != nil {
			//					log.Error("mail.daemon.workerDial.lastIDchanged.Close", "err", err) // no need to return
			//				}
			//				open = false
			//				// init new dialer
			//				dm.dialer = dialerPool.allocate(dm)
			//			}
			if open {
				if err := s.Close(); err != nil {
					PkgLog.Info("mail.daemon.workerDial.timeout.Close", "err", err)
					return err
				}
				open = false
			}
		}

	}
}