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