Skip to content

Commit

Permalink
fix: email header setting no longer misleading
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Oct 14, 2024
1 parent 8cc2f0e commit 767336c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
7 changes: 7 additions & 0 deletions internal/conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
"github.com/lestrrat-go/jwx/v2/jwk"
"gopkg.in/gomail.v2"
)

const defaultMinPasswordLength int = 6
Expand Down Expand Up @@ -352,6 +353,12 @@ func (c *SMTPConfiguration) Validate() error {
return nil
}

func (c *SMTPConfiguration) FromAddress() string {
mail := gomail.NewMessage()

return mail.FormatAddress(c.AdminEmail, c.SenderName)
}

type MailerConfiguration struct {
Autoconfirm bool `json:"autoconfirm"`
AllowUnverifiedEmailSignIns bool `json:"allow_unverified_email_sign_ins" split_words:"true" default:"false"`
Expand Down
13 changes: 1 addition & 12 deletions internal/mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"net/http"
"net/url"

"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
"github.com/supabase/auth/internal/conf"
"github.com/supabase/auth/internal/models"
"github.com/supabase/mailme"
"gopkg.in/gomail.v2"
)

// Mailer defines the interface a mailer must implement.
Expand Down Expand Up @@ -43,16 +41,7 @@ type EmailData struct {

// NewMailer returns a new gotrue mailer
func NewMailer(globalConfig *conf.GlobalConfiguration) Mailer {
mail := gomail.NewMessage()

mail.SetHeaders(map[string][]string{
// Make the emails explicitly set to be HTML formatted (to cover older email clients)
"Content-Type": {"text/html; charset=utf-8"},
// so that messages are not grouped under each other
"Message-ID": {fmt.Sprintf("<%s@gotrue-mailer>", uuid.Must(uuid.NewV4()).String())},
})

from := mail.FormatAddress(globalConfig.SMTP.AdminEmail, globalConfig.SMTP.SenderName)
from := globalConfig.SMTP.FromAddress()
u, _ := url.ParseRequestURI(globalConfig.API.ExternalURL)

var mailClient MailClient
Expand Down

0 comments on commit 767336c

Please sign in to comment.