appcore/email/message.go

45 lines
856 B
Go
Raw Normal View History

2025-06-16 22:19:00 +05:30
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
}