瀏覽代碼

Parse the from string to extract the email address

Peter 10 年之前
父節點
當前提交
c884ecfea1
共有 2 個文件被更改,包括 7 次插入2 次删除
  1. 1 1
      conf/app.ini
  2. 6 1
      modules/mailer/mailer.go

+ 1 - 1
conf/app.ini

@@ -98,7 +98,7 @@ SUBJECT = %(APP_NAME)s
 HOST =
 ; Do not verify the certificate of the server. Only use this for self-signed certificates
 SKIP_VERIFY = 
-; Mail from address. This can be just an email address, or the "Name" <[email protected]> format (including the quotes and brackets)
+; Mail from address, RFC 5322. This can be just an email address, or the "Name" <[email protected]> format 
 FROM =
 ; Mailer user name and password
 USER =

+ 6 - 1
modules/mailer/mailer.go

@@ -8,6 +8,7 @@ import (
 	"crypto/tls"
 	"fmt"
 	"net"
+	"net/mail"
 	"net/smtp"
 	"strings"
 
@@ -124,8 +125,12 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte)
 		}
 	}
 
-	if err = client.Mail(settings.From); err != nil {
+	if fromAddress, err := mail.ParseAddress(settings.From); err != nil {
 		return err
+	} else {
+		if err = client.Mail(fromAddress.Address); err != nil {
+			return err
+		}
 	}
 
 	for _, rec := range recipients {