diff --git a/email.go b/email.go index 052981e..3ff4d7b 100644 --- a/email.go +++ b/email.go @@ -15,17 +15,40 @@ type Email struct { From string Subject string Body string + + config *EmailConfig } -func NewEmail(to []string, from, subject, body string) *Email { +func NewEmail() *Email { return &Email{ - To: to, - From: from, - Subject: subject, - Body: body, + To: nil, + From: "", + Subject: "", + Body: "", + config: nil, } } +func (e *Email) Config(cfg *EmailConfig) { + e.config = cfg +} + +func (e *Email) SetFrom(from string) { + e.From = from +} + +func (e *Email) SetTo(to []string) { + e.To = to +} + +func (e *Email) SetSubject(sub string) { + e.Subject = sub +} + +func (e *Email) SetBody(body string) { + e.Body = body +} + func (e *Email) String() string { var str strings.Builder @@ -52,14 +75,11 @@ func (e *Email) Bytes() []byte { return []byte(e.String()) } -func SendEmail(email *Email, conf *EmailConfig) error { - if email == nil { - return errors.New("no email to send") - } - - if conf == nil { +func (email *Email) Send() error { + if email.config == nil { return errors.New("email configuration not provided") } + conf := email.config c, err := smtp.Dial(conf.ServerName) if err != nil {