This commit is contained in:
teddy
2025-04-18 21:36:12 +07:00
parent 90270a2ab8
commit 2a67bb260f
5 changed files with 70 additions and 59 deletions

View File

@@ -2,9 +2,11 @@ package helper
import (
"bytes"
"email-notification/config"
"fmt"
"html/template"
"log"
"net/smtp"
"time"
"github.com/google/uuid"
@@ -65,3 +67,21 @@ func FormatSince(t time.Time) string {
return "baru saja"
}
func SendEmail(to []string, cc []string, name, subject, message, htmlString string) error {
sender := "From: " + config.Mail().SMTPSenderName + "\n"
subjectt := "Subject: " + subject + "\n"
mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
body := htmlString
messages := []byte(sender + subjectt + mime + body)
auth := smtp.PlainAuth("", config.Mail().AuthEmail, config.Mail().AuthPassword, config.Mail().SMTPHost)
smtpAddr := fmt.Sprintf("%s:%d", config.Mail().SMTPHost, config.Mail().SMTPPort)
err := smtp.SendMail(smtpAddr, auth, config.Mail().AuthEmail, append(to, cc...), messages)
if err != nil {
return err
}
return nil
}