Add support for custom e-mail headers per SMTP server
This commit is contained in:
parent
82702ed5bc
commit
7a467a5a3b
|
@ -116,6 +116,10 @@ max_idle = 10
|
||||||
tls_enabled = true
|
tls_enabled = true
|
||||||
tls_skip_verify = false
|
tls_skip_verify = false
|
||||||
|
|
||||||
|
# One or more optional custom headers to be attached to all e-mails
|
||||||
|
# sent from this SMTP server. Uncomment the line to enable.
|
||||||
|
# email_headers = { "X-Sender" = "listmonk", "X-Custom-Header" = "listmonk" }
|
||||||
|
|
||||||
[smtp.postal]
|
[smtp.postal]
|
||||||
enabled = false
|
enabled = false
|
||||||
host = "my.smtp.server2"
|
host = "my.smtp.server2"
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
"net/textproto"
|
||||||
|
|
||||||
"github.com/jaytaylor/html2text"
|
"github.com/jaytaylor/html2text"
|
||||||
"github.com/knadh/smtppool"
|
"github.com/knadh/smtppool"
|
||||||
|
@ -21,6 +22,7 @@ type Server struct {
|
||||||
EmailFormat string `json:"email_format"`
|
EmailFormat string `json:"email_format"`
|
||||||
TLSEnabled bool `json:"tls_enabled"`
|
TLSEnabled bool `json:"tls_enabled"`
|
||||||
TLSSkipVerify bool `json:"tls_skip_verify"`
|
TLSSkipVerify bool `json:"tls_skip_verify"`
|
||||||
|
EmailHeaders map[string]string `json:"email_headers"`
|
||||||
|
|
||||||
// Rest of the options are embedded directly from the smtppool lib.
|
// Rest of the options are embedded directly from the smtppool lib.
|
||||||
// The JSON tag is for config unmarshal to work.
|
// The JSON tag is for config unmarshal to work.
|
||||||
|
@ -128,6 +130,14 @@ func (e *Emailer) Push(fromAddr string, toAddr []string, subject string, m []byt
|
||||||
Attachments: files,
|
Attachments: files,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there are custom e-mail headers, attach them.
|
||||||
|
if len(srv.EmailHeaders) > 0 {
|
||||||
|
em.Headers = textproto.MIMEHeader{}
|
||||||
|
for k, v := range srv.EmailHeaders {
|
||||||
|
em.Headers.Set(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch srv.EmailFormat {
|
switch srv.EmailFormat {
|
||||||
case "html":
|
case "html":
|
||||||
em.HTML = m
|
em.HTML = m
|
||||||
|
|
Loading…
Reference in New Issue