45 lines
856 B
Go
45 lines
856 B
Go
|
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
|
||
|
}
|