Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: email header setting no longer misleading #1802

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -353,6 +354,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,11 +5,9 @@ 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"
"gopkg.in/gomail.v2"
)

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

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

mail.SetHeaders(map[string][]string{
hf marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading