homebox/backend/pkgs/mailer/message.go
2024-05-24 19:46:30 -05:00

60 lines
1 KiB
Go

package mailer
import "net/mail"
type Message struct {
Subject string
To mail.Address
From mail.Address
Body string
}
func (m Message) ToAddresses() []string {
return []string{m.To.Address}
}
type MessageBuilder struct {
subject string
to mail.Address
from mail.Address
body string
}
func NewMessageBuilder() *MessageBuilder {
return &MessageBuilder{}
}
func (mb *MessageBuilder) Build() Message {
return Message{
Subject: mb.subject,
To: mb.to,
From: mb.from,
Body: mb.body,
}
}
func (mb *MessageBuilder) SetSubject(subject string) *MessageBuilder {
mb.subject = subject
return mb
}
func (mb *MessageBuilder) SetTo(name, to string) *MessageBuilder {
mb.to = mail.Address{
Name: name,
Address: to,
}
return mb
}
func (mb *MessageBuilder) SetFrom(name, from string) *MessageBuilder {
mb.from = mail.Address{
Name: name,
Address: from,
}
return mb
}
func (mb *MessageBuilder) SetBody(body string) *MessageBuilder {
mb.body = body
return mb
}