Esempio n. 1
0
func main() {

	fmt.Println("Start mailagent")

	user := flag.String("user", "", "Smtp user")
	pass := flag.String("pass", "", "Smtp password")
	timer := flag.Int("timer", 5, "timer in minutes")

	cfg := common.NewConfig()
	delay := time.Duration(*timer) * time.Minute

	db := common.NewDbClient(cfg.Service.Redis)

	if *user == "" || *pass == "" {
		fmt.Println("No user or password")
		return
	}

	execMe := func() {
		incomingFile := dumpIncoming(db)
		//acceptedFile := dumpAccepted(db)
		defer os.Remove(incomingFile)
		//		defer os.Remove(acceptedFile)

		md5Hash, err := ComputeMd5(incomingFile)
		if err == nil {
			if md5Hash != "" && prevMd5Hash == md5Hash {
				common.Trace.Println("Ignore sendign file. hashes the same: " + md5Hash)
				return
			}
			prevMd5Hash = md5Hash
		}
		err = sendEmail(*user, *pass, incomingFile /*, acceptedFile*/)
		if err != nil {
			fmt.Println("Send message error", err)
			return
		}
	}

	execMe()

	ticker := time.NewTicker(delay)
	go func() {
		for {
			select {
			case <-ticker.C:
				execMe()
			}
		}
	}()

	fmt.Println("press Ctrl+C")
	common.WaitCtrlC()

	ticker.Stop()
}
Esempio n. 2
0
package main

import "tad-demo/common"

var cfg = common.NewConfig()

// This module collects incomming phone numbers from the database and adds them to the conference call
// We need to have webserver to handle callback urls from RestComm and provide commands for it.

func main() {

	conference := Conference{}

	webServer := WebServer{callback: conference}
	webServer.Start()

	conference.RegisterNumber()

	conference.Subscribe()

	common.WaitCtrlC()
	common.Info.Println("Finished")
}