package socket
import (
"JISQueueing/common"
"bytes"
"github.com/spf13/viper"
"github.com/xhit/go-simple-mail"
"html/template"
"log"
"time"
)
var (
tmpl = template.New("email")
body = `
Hi {{{.Name}}},
Thank you for coming to the JIS IT Helpdesk.
Your queue number is {{{.ID}}}.
-
This message was automatically generated by The Dragon Queue.
Any questions? Please feel free to contact us
`
)
func sendMail(ticket common.Ticket) {
server := mail.NewSMTPClient()
server.Host = viper.GetString("mail.host")
server.Port = viper.GetInt("mail.port")
server.Username = viper.GetString("mail.username")
server.Encryption = mail.EncryptionNone
server.KeepAlive = false
server.ConnectTimeout = 10 * time.Second
server.SendTimeout = 10 * time.Second
client, err := server.Connect()
if err != nil {
log.Fatal(err)
}
email := mail.NewMSG()
t, _ := tmpl.Parse(body)
var result bytes.Buffer
t.Execute(&result, ticket)
email.
SetFrom("JIS Queuing HelpDesk").
AddTo(ticket.Email).
SetSubject("Thank you for coming to the JIS IT HelpDesk").
SetBody(mail.TextHTML, result.String()).
AddInline(viper.GetString("mail.logo"), "logo.svg")
err = email.Send(client)
if err != nil {
log.Println(err)
}
}