2022-08-30 02:30:36 +00:00
|
|
|
package mailer
|
|
|
|
|
|
|
|
import "net/mail"
|
|
|
|
|
|
|
|
type Message struct {
|
|
|
|
Subject string
|
|
|
|
To mail.Address
|
|
|
|
From mail.Address
|
|
|
|
Body string
|
|
|
|
}
|
|
|
|
|
2024-03-02 18:02:41 +00:00
|
|
|
func (m Message) ToAddresses() []string {
|
|
|
|
return []string{m.To.Address}
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:30:36 +00:00
|
|
|
type MessageBuilder struct {
|
|
|
|
subject string
|
|
|
|
to mail.Address
|
|
|
|
from mail.Address
|
|
|
|
body string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMessageBuilder() *MessageBuilder {
|
|
|
|
return &MessageBuilder{}
|
|
|
|
}
|
|
|
|
|
2024-03-02 18:02:41 +00:00
|
|
|
func (mb *MessageBuilder) Build() Message {
|
|
|
|
return Message{
|
2022-08-30 02:30:36 +00:00
|
|
|
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
|
|
|
|
}
|