79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
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 = `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
*{margin:0;padding:0}body{font-family:Helvetica,sans-serif}h2{font-size:2.25rem;padding:12px 0}h2 strong{color:#00509e}.desc{font-size:1.3rem;padding:32px 0}.desc h3{padding:6px 0}.bye{color:#555;font-style:italic}.dash{display:inline-block;padding-left:12px}.first{display:inline-block}.second{padding-left:22px}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h2>Hi <strong>{{{.Name}}}</strong>,</h2>
|
|
<div class="desc">
|
|
<h3>Thank you for coming to the JIS IT Helpdesk.</h3>
|
|
<h3>Your queue number is {{{.ID}}}.</h3>
|
|
</div>
|
|
<div class="bye">
|
|
<div class="dash">-</div>
|
|
<h4 class="first">This message was automatically generated by The Dragon Queue.</h4>
|
|
<h4 class="second"> Any questions? Please feel free to <a href="mailto:hgunawan@jisedu.or.id">contact us</a></h4>
|
|
<img src="cid:logo.svg" alt="JIS"/>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|
|
`
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|