diff --git a/email.go b/email.go index da4590e..a44b253 100644 --- a/email.go +++ b/email.go @@ -14,6 +14,7 @@ import ( "database/sql" "encoding/json" "fmt" + "github.com/writefreely/writefreely/mailer" "html/template" "net/http" "strings" @@ -437,17 +438,23 @@ func sendSubConfirmEmail(app *App, c *Collection, email, subID, token string) er } // Send email - gun := mailgun.NewMailgun(app.cfg.Email.Domain, app.cfg.Email.MailgunPrivate) + mlr, err := mailer.New(app.cfg.Email) + if err != nil { + return err + } plainMsg := "Confirm your subscription to " + c.DisplayTitle() + ` (` + c.CanonicalURL() + `) to start receiving future posts. Simply click the following link (or copy and paste it into your browser): ` + c.CanonicalURL() + "email/confirm/" + subID + "?t=" + token + ` If you didn't subscribe to this site or you're not sure why you're getting this email, you can delete it. You won't be subscribed or receive any future emails.` - m := mailgun.NewMessage(c.DisplayTitle()+" <"+c.Alias+"@"+app.cfg.Email.Domain+">", "Confirm your subscription to "+c.DisplayTitle(), plainMsg, fmt.Sprintf("<%s>", email)) + m, err := mlr.NewMessage(c.DisplayTitle()+" <"+c.Alias+"@"+app.cfg.Email.Domain+">", "Confirm your subscription to "+c.DisplayTitle(), plainMsg, fmt.Sprintf("<%s>", email)) + if err != nil { + return err + } m.AddTag("Email Verification") - m.SetHtml(` + m.SetHTML(`

Confirm your subscription to ` + c.DisplayTitle() + ` to start receiving future posts:

@@ -456,7 +463,10 @@ If you didn't subscribe to this site or you're not sure why you're getting this
`) - gun.Send(m) + err = mlr.Send(m) + if err != nil { + return err + } return nil } diff --git a/mailer/mailer.go b/mailer/mailer.go index fbc4dd6..1f9f86e 100644 --- a/mailer/mailer.go +++ b/mailer/mailer.go @@ -32,7 +32,7 @@ type ( ) // New creates a new Mailer from the instance's config.EmailCfg, returning an error if not properly configured. -func New(eCfg *config.EmailCfg) (*Mailer, error) { +func New(eCfg config.EmailCfg) (*Mailer, error) { m := &Mailer{} if eCfg.Domain != "" && eCfg.MailgunPrivate != "" { m.mailGun = mailgun.NewMailgun(eCfg.Domain, eCfg.MailgunPrivate) @@ -80,6 +80,13 @@ func (m *Message) SetHTML(html string) { } } +// AddTag attaches a tag to the Message for providers that support it. +func (m *Message) AddTag(tag string) { + if m.mgMsg != nil { + m.mgMsg.AddTag(tag) + } +} + // Send sends the given message via the preferred provider. func (m *Mailer) Send(msg *Message) error { if m.smtp != nil {