Browse Source

Added support for empty user domain in smtp

Toby Chui 10 months ago
parent
commit
a339b37323
3 changed files with 21 additions and 13 deletions
  1. 3 3
      emails.go
  2. 1 1
      main.go
  3. 17 9
      mod/email/email.go

+ 3 - 3
emails.go

@@ -27,8 +27,8 @@ func HandleSMTPSet(w http.ResponseWriter, r *http.Request) {
 
 	domain, err := utils.PostPara(r, "domain")
 	if err != nil {
-		utils.SendErrorResponse(w, "domain cannot be empty")
-		return
+		//Assume domain is empty, raised by issue #129
+		domain = ""
 	}
 
 	portString, err := utils.PostPara(r, "port")
@@ -206,7 +206,7 @@ var (
 )
 
 func HandleAdminAccountResetEmail(w http.ResponseWriter, r *http.Request) {
-	if EmailSender.Username == "" || EmailSender.Domain == "" {
+	if EmailSender.Username == "" {
 		//Reset account not setup
 		utils.SendErrorResponse(w, "Reset account not setup.")
 		return

+ 1 - 1
main.go

@@ -51,7 +51,7 @@ var logOutputToFile = flag.Bool("log", true, "Log terminal output to file")
 
 var (
 	name        = "Zoraxy"
-	version     = "3.0.2"
+	version     = "3.0.3"
 	nodeUUID    = "generic"
 	development = false //Set this to false to use embedded web fs
 	bootTime    = time.Now().Unix()

+ 17 - 9
mod/email/email.go

@@ -20,7 +20,7 @@ type Sender struct {
 	SenderAddr string //e.g. [email protected]
 }
 
-//Create a new email sender object
+// Create a new email sender object
 func NewEmailSender(hostname string, domain string, port int, username string, password string, senderAddr string) *Sender {
 	return &Sender{
 		Hostname:   hostname,
@@ -33,13 +33,15 @@ func NewEmailSender(hostname string, domain string, port int, username string, p
 }
 
 /*
-	Send a email to a reciving addr
-	Example Usage:
-	SendEmail(
-		[email protected],
-		"Free donuts",
-		"Come get your free donuts on this Sunday!"
-	)
+Send a email to a reciving addr
+Example Usage:
+SendEmail(
+
+	[email protected],
+	"Free donuts",
+	"Come get your free donuts on this Sunday!"
+
+)
 */
 func (s *Sender) SendEmail(to string, subject string, content string) error {
 	//Parse the email content
@@ -50,7 +52,13 @@ func (s *Sender) SendEmail(to string, subject string, content string) error {
 		content + "\n\n")
 
 	//Login to the SMTP server
-	auth := smtp.PlainAuth("", s.Username+"@"+s.Domain, s.Password, s.Hostname)
+	var auth smtp.Auth
+	if s.Domain == "" {
+		auth = smtp.PlainAuth("", s.Username, s.Password, s.Hostname)
+	} else {
+		auth = smtp.PlainAuth("", s.Username+"@"+s.Domain, s.Password, s.Hostname)
+	}
+
 	err := smtp.SendMail(s.Hostname+":"+strconv.Itoa(s.Port), auth, s.SenderAddr, []string{to}, msg)
 	if err != nil {
 		return err