chore: check slice length
This commit is contained in:
parent
3eec66e02b
commit
94afdc8e32
@ -14,10 +14,13 @@ func SendEmail(subject string, receiver string, content string) error {
|
|||||||
SMTPFrom = SMTPAccount
|
SMTPFrom = SMTPAccount
|
||||||
}
|
}
|
||||||
encodedSubject := fmt.Sprintf("=?UTF-8?B?%s?=", base64.StdEncoding.EncodeToString([]byte(subject)))
|
encodedSubject := fmt.Sprintf("=?UTF-8?B?%s?=", base64.StdEncoding.EncodeToString([]byte(subject)))
|
||||||
|
|
||||||
// Extract domain from SMTPFrom
|
|
||||||
domain := strings.Split(SMTPFrom, "@")[1]
|
|
||||||
|
|
||||||
|
// Extract domain from SMTPFrom
|
||||||
|
parts := strings.Split(SMTPFrom, "@")
|
||||||
|
var domain string
|
||||||
|
if len(parts) > 1 {
|
||||||
|
domain = parts[1]
|
||||||
|
}
|
||||||
// Generate a unique Message-ID
|
// Generate a unique Message-ID
|
||||||
buf := make([]byte, 16)
|
buf := make([]byte, 16)
|
||||||
_, err := rand.Read(buf)
|
_, err := rand.Read(buf)
|
||||||
@ -29,7 +32,7 @@ func SendEmail(subject string, receiver string, content string) error {
|
|||||||
mail := []byte(fmt.Sprintf("To: %s\r\n"+
|
mail := []byte(fmt.Sprintf("To: %s\r\n"+
|
||||||
"From: %s<%s>\r\n"+
|
"From: %s<%s>\r\n"+
|
||||||
"Subject: %s\r\n"+
|
"Subject: %s\r\n"+
|
||||||
"Message-ID: %s\r\n"+ // Add Message-ID to avoid being treated as spam, RFC 5322
|
"Message-ID: %s\r\n"+ // add Message-ID header to avoid being treated as spam, RFC 5322
|
||||||
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
|
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
|
||||||
receiver, SystemName, SMTPFrom, encodedSubject, messageId, content))
|
receiver, SystemName, SMTPFrom, encodedSubject, messageId, content))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user