38 lines
777 B
Go
38 lines
777 B
Go
package mailer
|
|
|
|
import (
|
|
"net/smtp"
|
|
|
|
"clickandjoin.app/emailserver/modules/cache"
|
|
"clickandjoin.app/emailserver/modules/config"
|
|
"clickandjoin.app/emailserver/modules/structs"
|
|
gocnjhelper "git.ex.umbach.dev/ClickandJoin/go-cnj-helper"
|
|
)
|
|
|
|
func Init() {
|
|
cfg := config.Cfg.Mail
|
|
|
|
cache.SmtpAuth = smtp.PlainAuth("", cfg.Username, cfg.Password, cfg.Host)
|
|
|
|
readTemplatesConfig()
|
|
loadTemplateFiles()
|
|
}
|
|
|
|
func NewMail(mail structs.Mail) error {
|
|
gocnjhelper.LogDebug("NEW MAIL")
|
|
|
|
htmlBody, textBody, err := mail.RenderTemplate()
|
|
|
|
if err != nil {
|
|
gocnjhelper.LogErrorf("Failed to render template, err: %s", err)
|
|
return err
|
|
}
|
|
|
|
if err = mail.Send(htmlBody, textBody); err != nil {
|
|
gocnjhelper.LogErrorf("Failed to send mail, err: %s", err)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|