| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package main
- import(
- "crypto/tls"
- "strings"
- "gopkg.in/gomail.v2"
- "966.it/ini"
- "966.it/opt"
- "fmt"
- //"os"
- )
- func main() {
- //var cfg *ini.File
- // var struttura optp.IniStru
- struttura := optp.Start()
- fmt.Println("parametri:",struttura)
- iniFile := struttura.IniFile
- fmt.Println("parametro passato",iniFile)
- inip.GetIni(*iniFile)
- _ = inip.LoadIni()
- // sezione di prova per vedere cosa ritorna dal file
- fmt.Println(inip.GetMySection())
- /*
- var err error
- mymail,err = cfg.GetSection("mail")
- if err != nil {
- fmt.Println("Errore nella lettura della sezione")
- fmt.Println(err)
- os.Exit(99)
- }
- var mymail *ini.Section
- keys := mymail.KeyStrings()
- for _,x := range keys {
- fmt.Println(x)
- }
- */
- 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(",")
- protocol := inip.GetMyKey("mail","protocol").String()
- _subject := inip.GetMyKey("mail","_subject").String()
- _body := inip.GetMyKey("mail","_text").String()
- // sostituisco alcuni valori con quelli passati da iniStru
- if len(*struttura.IniFrom) > 0 {
- _from = *struttura.IniFrom
- }
- if len(*struttura.IniTo) > 0 {
- _to = strings.Split(*struttura.IniTo,",")
- }
- if len(*struttura.IniSubject) > 0 {
- _subject = *struttura.IniSubject
- }
- if len(*struttura.IniBody) > 0 {
- _body = *struttura.IniBody
- }
- for _,tos := range _to {
- m := gomail.NewMessage()
- m.SetHeader("From",_from)
- m.SetHeader("To",tos)
- m.SetHeader("Subject",_subject)
- m.SetBody("Text/plain",_body)
- d := gomail.NewDialer(server,porta,username,password)
- if protocol == "ssl" {
- d.SSL=true
- } else if protocol == "tls" {
- d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
- }
- // Send the email to Bob, Cora and Dan.
- if err := d.DialAndSend(m); err != nil {
- panic(err)
- }
- }
- }
|