Skip to content

Commit

Permalink
Use proper Subject header
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.ru>
  • Loading branch information
teran committed May 7, 2018
1 parent d5d020d commit e1bc8cb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/mailgun/mailgun.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"log"
"net/mail"

smtp "github.com/emersion/go-smtp"
mg "gopkg.in/mailgun/mailgun-go.v1"
Expand Down Expand Up @@ -49,18 +50,23 @@ func (b *Backend) AnonymousLogin() (smtp.User, error) {
}

func (u *User) Send(from string, to []string, r io.Reader) error {
mBody, err := ioutil.ReadAll(r)
m, err := mail.ReadMessage(r)
if err != nil {
return err
}

mBody, err := ioutil.ReadAll(m.Body)
if err != nil {
return err
}

for _, recipient := range to {
message := u.mailgunClient.NewMessage(from, "subject", string(mBody), recipient)
message := u.mailgunClient.NewMessage(from, m.Header.Get("Subject"), string(mBody), recipient)
resp, id, err := u.mailgunClient.Send(message)
if err != nil {
return err
}
log.Printf("ID: %s Resp: %s\n", id, resp)
log.Printf("ID: %s Resp: %s", id, resp)
}
return nil
}
Expand Down

0 comments on commit e1bc8cb

Please sign in to comment.