mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-04 15:39:45 +00:00
fix: emails are considered as medium spam by rspamd (#337)
This commit is contained in:
committed by
GitHub
parent
e45d9e970d
commit
39b7f6678c
@@ -18,6 +18,8 @@ import (
|
||||
"os"
|
||||
ttemplate "text/template"
|
||||
"time"
|
||||
"github.com/google/uuid"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EmailService struct {
|
||||
@@ -84,6 +86,29 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
|
||||
c.AddHeaderRaw("Content-Type",
|
||||
fmt.Sprintf("multipart/alternative;\n boundary=%s;\n charset=UTF-8", boundary),
|
||||
)
|
||||
|
||||
c.AddHeader("MIME-Version", "1.0")
|
||||
c.AddHeader("Date", time.Now().Format(time.RFC1123Z))
|
||||
|
||||
// to create a message-id, we need the FQDN of the sending server, but that may be a docker hostname or localhost
|
||||
// so we use the domain of the from address instead (the same as Thunderbird does)
|
||||
// if the address does not have an @ (which would be unusual), we use hostname
|
||||
|
||||
from_address := srv.appConfigService.DbConfig.SmtpFrom.Value
|
||||
domain := ""
|
||||
if strings.Contains(from_address, "@") {
|
||||
domain = strings.Split(from_address, "@")[1]
|
||||
} else {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
// can that happen? we just give up
|
||||
return fmt.Errorf("failed to get own hostname: %w", err)
|
||||
} else {
|
||||
domain = hostname
|
||||
}
|
||||
}
|
||||
c.AddHeader("Message-ID", "<" + uuid.New().String() + "@" + domain + ">")
|
||||
|
||||
c.Body(body)
|
||||
|
||||
// Connect to the SMTP server
|
||||
|
||||
Reference in New Issue
Block a user