|
|
|
@ -6,9 +6,17 @@ import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"github.com/redis/go-redis/v9" |
|
|
|
"github.com/redis/go-redis/v9" |
|
|
|
|
|
|
|
"github.com/gofiber/template/html/v2" |
|
|
|
"MY/webapp/config" |
|
|
|
"MY/webapp/config" |
|
|
|
|
|
|
|
"strings" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var HTMLTemplates *html.Engine |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
|
|
|
HTMLTemplates = html.New("./emails", ".html") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewSender(ctx context.Context) (Sender){ |
|
|
|
func NewSender(ctx context.Context) (Sender){ |
|
|
|
client := redis.NewClient(&redis.Options{ |
|
|
|
client := redis.NewClient(&redis.Options{ |
|
|
|
Addr: config.Settings.Redis.HostPort, |
|
|
|
Addr: config.Settings.Redis.HostPort, |
|
|
|
@ -56,8 +64,10 @@ func (router *Router) DeliverEmail(msg EmailMessage) error { |
|
|
|
if err != nil { return err } |
|
|
|
if err != nil { return err } |
|
|
|
|
|
|
|
|
|
|
|
email_msg.Subject(msg.Subject) |
|
|
|
email_msg.Subject(msg.Subject) |
|
|
|
email_msg.SetBodyString(mail.TypeTextPlain, msg.Text) |
|
|
|
|
|
|
|
email_msg.SetBodyString(mail.TypeTextHTML, msg.HTML) |
|
|
|
out := new(strings.Builder) |
|
|
|
|
|
|
|
err = HTMLTemplates.Render(out, msg.HTMLTemplate, msg.Data) |
|
|
|
|
|
|
|
email_msg.SetBodyString(mail.TypeTextHTML, out.String()) |
|
|
|
|
|
|
|
|
|
|
|
if config.Settings.Email.XMailer != "" { |
|
|
|
if config.Settings.Email.XMailer != "" { |
|
|
|
email_msg.SetGenHeader(mail.HeaderXMailer, config.Settings.Email.XMailer) |
|
|
|
email_msg.SetGenHeader(mail.HeaderXMailer, config.Settings.Email.XMailer) |
|
|
|
|