restructure hardlink layout
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.futuresens.co.uk/futuresens/logging"
|
||||
mailjet "github.com/mailjet/mailjet-apiv3-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
apiKey = "60f358a27e98562641c08f51e5450c9e"
|
||||
secretKey = "068b65c3b337a0e3c14389544ecd771f"
|
||||
)
|
||||
|
||||
const (
|
||||
moduleName = "mail"
|
||||
)
|
||||
|
||||
var (
|
||||
// sendErrorEmail is the e-mail address to which to send an e-mail if there is an error during checkin or payment
|
||||
SendErrorEmails []string
|
||||
)
|
||||
|
||||
// SendMail will send reception an e-mail
|
||||
func SendMail(recipient, title, message string) {
|
||||
const funcName = "SendMail"
|
||||
|
||||
mailjetClient := mailjet.NewMailjetClient(apiKey, secretKey)
|
||||
messagesInfo := []mailjet.InfoMessagesV31{
|
||||
mailjet.InfoMessagesV31{
|
||||
From: &mailjet.RecipientV31{
|
||||
Email: "kiosk@cms.futuresens.co.uk",
|
||||
Name: "Futuresens Kiosk",
|
||||
},
|
||||
To: &mailjet.RecipientsV31{
|
||||
mailjet.RecipientV31{
|
||||
Email: recipient,
|
||||
Name: "",
|
||||
},
|
||||
},
|
||||
Subject: title,
|
||||
TextPart: message,
|
||||
},
|
||||
}
|
||||
messages := mailjet.MessagesV31{Info: messagesInfo}
|
||||
_, err := mailjetClient.SendMailV31(&messages)
|
||||
if err != nil {
|
||||
theFields := log.Fields{}
|
||||
theFields["mailerror"] = true
|
||||
theFields["recipient"] = recipient
|
||||
theFields[logging.LogFunction] = funcName
|
||||
theFields[logging.LogModule] = moduleName
|
||||
theFields[logging.LogError] = err.Error()
|
||||
theFields["error"] = err.Error()
|
||||
|
||||
log.WithFields(theFields).Error("sendmail error")
|
||||
}
|
||||
}
|
||||
|
||||
func SendEmailOnError(hotel string, kiosk int, title, errMsg string) {
|
||||
log.Println("sendEmailOnError called")
|
||||
|
||||
message := fmt.Sprintf("Hotel: %s, kiosk: %d.\n%s", hotel, kiosk, errMsg)
|
||||
for _, recipient := range SendErrorEmails {
|
||||
SendMail(recipient, title, message)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_SendMail(t *testing.T) {
|
||||
SendMail("zotacrtx5@gmail.com", "Test Subjectp", "Test Message")
|
||||
}
|
||||
Reference in New Issue
Block a user