|
|
@@ -3,6 +3,7 @@ import(
|
|
|
//"crypto/tls"
|
|
|
"gopkg.in/gomail.v2"
|
|
|
"966.it/ini"
|
|
|
+ "966.it/opt"
|
|
|
"gopkg.in/ini.v1"
|
|
|
"fmt"
|
|
|
"os"
|
|
|
@@ -13,26 +14,24 @@ func main() {
|
|
|
var mymail *ini.Section
|
|
|
var err error
|
|
|
|
|
|
- fmt.Println(len(os.Args))
|
|
|
- if len(os.Args) > 1 && len(os.Args) < 4 {
|
|
|
- fmt.Println("parametro passato",os.Args[1])
|
|
|
- inip.GetIni(os.Args[1])
|
|
|
- cfg = inip.LoadIni()
|
|
|
+ iniFile := optp.Start()
|
|
|
+ fmt.Println("parametro passato",iniFile)
|
|
|
+ inip.GetIni(iniFile)
|
|
|
+ cfg = inip.LoadIni()
|
|
|
|
|
|
- // sezione di prova per vedere cosa ritorna dal file
|
|
|
- fmt.Println(inip.GetMySection())
|
|
|
+ // sezione di prova per vedere cosa ritorna dal file
|
|
|
+ fmt.Println(inip.GetMySection())
|
|
|
|
|
|
- mymail,err = cfg.GetSection("mail")
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Errore nella lettura della sezione")
|
|
|
- fmt.Println(err)
|
|
|
- os.Exit(99)
|
|
|
- }
|
|
|
+ mymail,err = cfg.GetSection("mail")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Errore nella lettura della sezione")
|
|
|
+ fmt.Println(err)
|
|
|
+ os.Exit(99)
|
|
|
}
|
|
|
|
|
|
- keys := mymail.KeyStrings()
|
|
|
+keys := mymail.KeyStrings()
|
|
|
|
|
|
- for _,x := range keys {
|
|
|
+for _,x := range keys {
|
|
|
fmt.Println(x)
|
|
|
}
|
|
|
|
|
|
@@ -40,25 +39,31 @@ func main() {
|
|
|
// che sia in grado di scorrere l'elenco delle chiavi e nel caso ne trovi una
|
|
|
// che corrisponde, assegnarla alla relativa variabile
|
|
|
|
|
|
-var _from string = "acliservice@altemica.local"
|
|
|
-var _to string = "server@altemica.net"
|
|
|
-var _subject string ="Acliserver in avvio..."
|
|
|
-var _body string ="Acliserver in avvio..."
|
|
|
-
|
|
|
+server := inip.GetMyKey("mail","server").String()
|
|
|
+porta,_ := inip.GetMyKey("mail","porta").Int()
|
|
|
+username := inip.GetMyKey("mail","username").String()
|
|
|
+password := inip.GetMyKey("mail","password").String()
|
|
|
+_from := inip.GetMyKey("mail","_from").String()
|
|
|
+_to := inip.GetMyKey("mail","_to").Strings(",")
|
|
|
|
|
|
+_subject := inip.GetMyKey("mail","_subject").String()
|
|
|
+_body := inip.GetMyKey("mail","_text").String()
|
|
|
|
|
|
+for _,tos := range _to {
|
|
|
m := gomail.NewMessage()
|
|
|
m.SetHeader("From",_from)
|
|
|
- m.SetHeader("To",_to)
|
|
|
+ m.SetHeader("To",tos)
|
|
|
m.SetHeader("Subject",_subject)
|
|
|
m.SetBody("Text/Text",_body)
|
|
|
|
|
|
- d := gomail.NewDialer("localhost",465,"acliservice@altemica.local","uei551hex")
|
|
|
+ d := gomail.NewDialer(server,porta,username,password)
|
|
|
d.SSL=true
|
|
|
+
|
|
|
//d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
|
|
|
|
|
// Send the email to Bob, Cora and Dan.
|
|
|
if err := d.DialAndSend(m); err != nil {
|
|
|
- panic(err)
|
|
|
+ panic(err)
|
|
|
}
|
|
|
}
|
|
|
+}
|