|
@@ -6,8 +6,18 @@ import(
|
|
|
"966.it/ini"
|
|
"966.it/ini"
|
|
|
"966.it/opt"
|
|
"966.it/opt"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- //"os"
|
|
|
|
|
|
|
+ "os"
|
|
|
|
|
+ "bufio"
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+func magagna(err error) bool {
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ return false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func main() {
|
|
func main() {
|
|
|
|
|
|
|
|
//var cfg *ini.File
|
|
//var cfg *ini.File
|
|
@@ -16,14 +26,16 @@ func main() {
|
|
|
struttura := optp.Start()
|
|
struttura := optp.Start()
|
|
|
fmt.Println("parametri:",struttura)
|
|
fmt.Println("parametri:",struttura)
|
|
|
|
|
|
|
|
|
|
+ // questo parametro è fondamentale, indica il file di configurazione
|
|
|
iniFile := struttura.IniFile
|
|
iniFile := struttura.IniFile
|
|
|
-
|
|
|
|
|
fmt.Println("parametro passato",iniFile)
|
|
fmt.Println("parametro passato",iniFile)
|
|
|
|
|
+
|
|
|
inip.GetIni(*iniFile)
|
|
inip.GetIni(*iniFile)
|
|
|
_ = inip.LoadIni()
|
|
_ = inip.LoadIni()
|
|
|
|
|
|
|
|
// sezione di prova per vedere cosa ritorna dal file
|
|
// sezione di prova per vedere cosa ritorna dal file
|
|
|
- fmt.Println(inip.GetMySection())
|
|
|
|
|
|
|
+ //fmt.Println(inip.GetMySection())
|
|
|
|
|
+ inip.GetMySection()
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
var err error
|
|
var err error
|
|
@@ -42,16 +54,19 @@ for _,x := range keys {
|
|
|
}
|
|
}
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-
|
|
|
|
|
server := inip.GetMyKey("mail","server").String()
|
|
server := inip.GetMyKey("mail","server").String()
|
|
|
porta,_ := inip.GetMyKey("mail","porta").Int()
|
|
porta,_ := inip.GetMyKey("mail","porta").Int()
|
|
|
|
|
+authentication := inip.GetMyKey("mail","authentication").String()
|
|
|
username := inip.GetMyKey("mail","username").String()
|
|
username := inip.GetMyKey("mail","username").String()
|
|
|
password := inip.GetMyKey("mail","password").String()
|
|
password := inip.GetMyKey("mail","password").String()
|
|
|
_from := inip.GetMyKey("mail","_from").String()
|
|
_from := inip.GetMyKey("mail","_from").String()
|
|
|
_to := inip.GetMyKey("mail","_to").Strings(",")
|
|
_to := inip.GetMyKey("mail","_to").Strings(",")
|
|
|
protocol := inip.GetMyKey("mail","protocol").String()
|
|
protocol := inip.GetMyKey("mail","protocol").String()
|
|
|
_subject := inip.GetMyKey("mail","_subject").String()
|
|
_subject := inip.GetMyKey("mail","_subject").String()
|
|
|
-_body := inip.GetMyKey("mail","_text").String()
|
|
|
|
|
|
|
+_body := inip.GetMyKey("mail","_body").String()
|
|
|
|
|
+_source := inip.GetMyKey("mail","_source").String()
|
|
|
|
|
+
|
|
|
|
|
+fmt.Println("dalla configurazione:",_source)
|
|
|
|
|
|
|
|
// sostituisco alcuni valori con quelli passati da iniStru
|
|
// sostituisco alcuni valori con quelli passati da iniStru
|
|
|
if len(*struttura.IniFrom) > 0 {
|
|
if len(*struttura.IniFrom) > 0 {
|
|
@@ -66,6 +81,9 @@ if len(*struttura.IniSubject) > 0 {
|
|
|
if len(*struttura.IniBody) > 0 {
|
|
if len(*struttura.IniBody) > 0 {
|
|
|
_body = *struttura.IniBody
|
|
_body = *struttura.IniBody
|
|
|
}
|
|
}
|
|
|
|
|
+if len(*struttura.IniSource) > 0 {
|
|
|
|
|
+ _source = *struttura.IniSource
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
for _,tos := range _to {
|
|
for _,tos := range _to {
|
|
|
m := gomail.NewMessage()
|
|
m := gomail.NewMessage()
|
|
@@ -74,17 +92,52 @@ for _,tos := range _to {
|
|
|
m.SetHeader("Subject",_subject)
|
|
m.SetHeader("Subject",_subject)
|
|
|
m.SetBody("Text/plain",_body)
|
|
m.SetBody("Text/plain",_body)
|
|
|
|
|
|
|
|
- d := gomail.NewDialer(server,porta,username,password)
|
|
|
|
|
|
|
+ var body string
|
|
|
|
|
+
|
|
|
|
|
+ if len(_source) > 0 {
|
|
|
|
|
+ fmt.Println("Lettura file",_source)
|
|
|
|
|
+ f,err := os.Open(_source)
|
|
|
|
|
+ if magagna(err) {
|
|
|
|
|
+ fmt.Println("Errore di apertura file ",_source)
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ //m.SetBody("Text/Plain",err)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Println("Scanning file")
|
|
|
|
|
+ myr := bufio.NewScanner(f)
|
|
|
|
|
+ for myr.Scan() {
|
|
|
|
|
+ body += myr.Text()
|
|
|
|
|
+ body += "\n"
|
|
|
|
|
+ if magagna(err) {
|
|
|
|
|
+ fmt.Println("Errore lettura file",_source)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Println(body)
|
|
|
|
|
+ m.SetBody("Text/Plain",body)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var d *gomail.Dialer
|
|
|
|
|
+
|
|
|
|
|
+ if authentication == "yes" {
|
|
|
|
|
+ d = gomail.NewDialer(server,porta,username,password)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ d = new(gomail.Dialer)
|
|
|
|
|
+ d.Host = server
|
|
|
|
|
+ d.Port = porta
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if protocol == "ssl" {
|
|
if protocol == "ssl" {
|
|
|
d.SSL=true
|
|
d.SSL=true
|
|
|
} else if protocol == "tls" {
|
|
} else if protocol == "tls" {
|
|
|
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
|
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// Send the email to Bob, Cora and Dan.
|
|
// Send the email to Bob, Cora and Dan.
|
|
|
if err := d.DialAndSend(m); err != nil {
|
|
if err := d.DialAndSend(m); err != nil {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|