update
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user