appcore/email/message.go
2025-06-16 22:26:47 +05:30

50 lines
1.0 KiB
Go

// Copyright 2024 Patial Tech (Ankit Patial).
//
// This file is part of code.patial.tech/go/appcore, which is MIT licensed.
// See http://opensource.org/licenses/MIT
package email
import (
"errors"
"net/mail"
)
type Message struct {
ReplyTo *mail.Address `json:"replyTo"`
ID string
From string `json:"from"`
Subject string `json:"subject"`
HtmlBody string `json:"htmlBody"`
TxtBody string `json:"txtBody"`
To []mail.Address `json:"to"`
Cc []mail.Address `json:"cc"`
Bcc []mail.Address `json:"bcc"`
}
func (m *Message) Validate() error {
if m == nil {
return errors.New("email: message is nil")
}
if len(m.To) == 0 {
return errors.New("email: message must have at least one recipient")
}
if len(m.From) == 0 {
return errors.New("email: message must have a sender")
}
if len(m.Subject) == 0 {
return errors.New("email: message must have a subject")
}
if len(m.HtmlBody) == 0 && len(m.TxtBody) == 0 {
return errors.New("email: message must have a body")
}
return nil
}