Add fieldName when constructing SmtpMessage + go fmt

pull/1153/head
Jean-Baptiste Giraudeau 6 days ago
parent 63963b6b19
commit 0f9c32161c
No known key found for this signature in database
GPG Key ID: 7CEF8C9CC2D9933B
  1. 2
      config/config.go
  2. 36
      mailer/mailer.go
  3. 2
      templates.go

@ -252,7 +252,7 @@ func (ac *AppCfg) LandingPath() string {
func (lc EmailCfg) Enabled() bool { func (lc EmailCfg) Enabled() bool {
return (lc.Domain != "" && lc.MailgunPrivate != "") || return (lc.Domain != "" && lc.MailgunPrivate != "") ||
lc.Username != "" && lc.Password != "" && lc.Host != "" && lc.Port > 0 lc.Username != "" && lc.Password != "" && lc.Host != "" && lc.Port > 0
} }
func (ac AppCfg) SignupPath() string { func (ac AppCfg) SignupPath() string {

@ -12,11 +12,11 @@ package mailer
import ( import (
"fmt" "fmt"
"strings"
"github.com/mailgun/mailgun-go" "github.com/mailgun/mailgun-go"
"github.com/writefreely/writefreely/config"
"github.com/writeas/web-core/log" "github.com/writeas/web-core/log"
"github.com/writefreely/writefreely/config"
mail "github.com/xhit/go-simple-mail/v2" mail "github.com/xhit/go-simple-mail/v2"
"strings"
) )
type ( type (
@ -33,17 +33,17 @@ type (
} }
SmtpMessage struct { SmtpMessage struct {
from string from string
replyTo string replyTo string
subject string subject string
recipients []Recipient recipients []Recipient
html string html string
text string text string
} }
Recipient struct { Recipient struct {
email string email string
vars map[string]string vars map[string]string
} }
) )
@ -79,13 +79,13 @@ func (m *Mailer) NewMessage(from, subject, text string, to ...string) (*Message,
if m.mailGun != nil { if m.mailGun != nil {
msg.mgMsg = m.mailGun.NewMessage(from, subject, text, to...) msg.mgMsg = m.mailGun.NewMessage(from, subject, text, to...)
} else if m.smtp != nil { } else if m.smtp != nil {
msg.smtpMsg = &SmtpMessage { msg.smtpMsg = &SmtpMessage{
from, from: from,
"", replyTo: "",
subject, subject: subject,
make([]Recipient, len(to)), recipients: make([]Recipient, len(to)),
"", html: "",
text, text: text,
} }
for _, r := range to { for _, r := range to {
msg.smtpMsg.recipients = append(msg.smtpMsg.recipients, Recipient{r, make(map[string]string)}) msg.smtpMsg.recipients = append(msg.smtpMsg.recipients, Recipient{r, make(map[string]string)})
@ -104,7 +104,7 @@ func (m *Message) SetHTML(html string) {
} }
func (m *Message) SetReplyTo(replyTo string) { func (m *Message) SetReplyTo(replyTo string) {
if (m.smtpMsg != nil) { if m.smtpMsg != nil {
m.smtpMsg.replyTo = replyTo m.smtpMsg.replyTo = replyTo
} else { } else {
m.mgMsg.SetReplyTo(replyTo) m.mgMsg.SetReplyTo(replyTo)
@ -142,7 +142,7 @@ func (m *Mailer) Send(msg *Message) error {
for _, r := range msg.smtpMsg.recipients { for _, r := range msg.smtpMsg.recipients {
customMsg := mail.NewMSG() customMsg := mail.NewMSG()
customMsg.SetFrom(msg.smtpMsg.from) customMsg.SetFrom(msg.smtpMsg.from)
if (msg.smtpMsg.replyTo != "") { if msg.smtpMsg.replyTo != "" {
customMsg.SetReplyTo(msg.smtpMsg.replyTo) customMsg.SetReplyTo(msg.smtpMsg.replyTo)
} }
customMsg.SetSubject(msg.smtpMsg.subject) customMsg.SetSubject(msg.smtpMsg.subject)
@ -163,7 +163,7 @@ func (m *Mailer) Send(msg *Message) error {
if e == nil { if e == nil {
emailSent = true emailSent = true
} else { } else {
log.Error("Unable to send email to %s: %v", r.email, e) log.Error("Unable to send email to %s: %v", r.email, e)
err = e err = e
} }
} }

@ -14,8 +14,8 @@ import (
"errors" "errors"
"html/template" "html/template"
"io" "io"
"os"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"strings" "strings"

Loading…
Cancel
Save