basic common app packages
This commit is contained in:
44
email/message.go
Normal file
44
email/message.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user