todoapp/events/eventjobs/send-welcome-email.go
2024-09-15 13:36:50 -05:00

31 lines
784 B
Go

package eventjobs
import (
"fmt"
"git.smarteching.com/goffee/core"
"git.smarteching.com/goffee/todoapp/models"
)
var SendWelcomeEmail core.EventJob = func(event *core.Event, c *core.Context) {
go func() {
mailer := c.GetMailer()
logger := c.GetLogger()
user, ok := event.Payload["user"].(models.User)
if !ok {
logger.Error("[SenEmail job] invalid user")
return
}
mailer.SetFrom(core.EmailAddress{Name: "GoCondor", Address: "mail@example.com"})
mailer.SetTo([]core.EmailAddress{
{
Name: user.Name, Address: user.Email,
},
})
mailer.SetSubject("Welcome To GoCondor")
body := fmt.Sprintf("Hi %v, \nWelcome to GoCondor \nYour account have been created successfully. \nThanks.", user.Name)
mailer.SetPlainTextBody(body)
mailer.Send()
}()
}