change receiver field type
This commit is contained in:
parent
2bc22b637d
commit
4d0076e625
17
mail/mail.go
17
mail/mail.go
@ -10,20 +10,11 @@ import (
|
||||
type Email struct {
|
||||
Path string
|
||||
Sender string `json:"sender"`
|
||||
Receivers []string `json:"receivers"`
|
||||
Receivers string `json:"receivers"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func NewEmail(sender string, receivers []string, subject, content string) Email {
|
||||
return Email{
|
||||
Sender: sender,
|
||||
Receivers: receivers,
|
||||
Subject: subject,
|
||||
Content: content,
|
||||
}
|
||||
}
|
||||
|
||||
func FromJSON(path string) (Email, error) {
|
||||
var mail Email
|
||||
|
||||
@ -39,10 +30,14 @@ func FromJSON(path string) (Email, error) {
|
||||
return mail, nil
|
||||
}
|
||||
|
||||
func (e Email) GetReceivers() []string {
|
||||
return strings.Split(e.Receivers, ",")
|
||||
}
|
||||
|
||||
func (e Email) Generate() []byte {
|
||||
mail := fmt.Sprintf(
|
||||
"To: %s\nFrom: %s\nContent-Type: text/html;charset=utf-8\nSubject: %s\n\n%s",
|
||||
strings.Join(e.Receivers, ","),
|
||||
e.Receivers,
|
||||
e.Sender,
|
||||
e.Subject,
|
||||
e.Content,
|
||||
|
||||
@ -42,7 +42,7 @@ func (s Sender) SendMail(email mail.Email) error {
|
||||
auth := smtp.PlainAuth("", s.smtpConfig.User, s.smtpConfig.Password, s.smtpConfig.Url)
|
||||
log.Debug().Msg("SMTP authentication succeed")
|
||||
|
||||
if err := smtp.SendMail(s.smtpConfig.GetFullUrl(), auth, email.Sender, email.Receivers, email.Generate()); err != nil {
|
||||
if err := smtp.SendMail(s.smtpConfig.GetFullUrl(), auth, email.Sender, email.GetReceivers(), email.Generate()); err != nil {
|
||||
log.Err(err).Msg("error while sending email")
|
||||
return err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user