Browse Source

Fix smtp server stuck of sending

Vova Tkach 5 years ago
parent
commit
0064385c1b
2 changed files with 14 additions and 4 deletions
  1. 13 3
      engine/wrapper/wrapper.go
  2. 1 1
      smtp.go

+ 13 - 3
engine/wrapper/wrapper.go

@@ -287,7 +287,7 @@ func (this *Wrapper) ConfigSave() error {
 }
 
 func (this *Wrapper) SendEmailUsual(email, subject, message string) error {
-	if !((*this.Config).SMTP.Host != "" && (*this.Config).SMTP.Login != "" && (*this.Config).SMTP.Password != "") {
+	if (*this.Config).SMTP.Host == "" || (*this.Config).SMTP.Login == "" || (*this.Config).SMTP.Password == "" {
 		return errors.New("SMTP server is not configured")
 	}
 
@@ -332,20 +332,30 @@ func (this *Wrapper) SendEmailUsual(email, subject, message string) error {
 }
 
 func (this *Wrapper) SendEmailFast(email, subject, message string) error {
+	status := 2
+	emessage := ""
+
+	if (*this.Config).SMTP.Host == "" || (*this.Config).SMTP.Login == "" || (*this.Config).SMTP.Password == "" {
+		status = 0
+		emessage = "SMTP server is not configured"
+	}
+
 	if _, err := this.DB.Exec(
 		`INSERT INTO notify_mail SET
 			id = NULL,
 			email = ?,
 			subject = ?,
 			message = ?,
-			error = '',
+			error = ?,
 			datetime = ?,
-			status = 2
+			status = ?
 		;`,
 		email,
 		subject,
 		message,
+		emessage,
 		utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
+		status,
 	); err != nil {
 		return err
 	}

+ 1 - 1
smtp.go

@@ -93,7 +93,7 @@ func smtp_process(dir, host string, mp *mysqlpool.MySqlPool) {
 	if db != nil {
 		conf := config.ConfigNew()
 		if err := conf.ConfigRead(strings.Join([]string{dir, "config", "config.json"}, string(os.PathSeparator))); err == nil {
-			if (*conf).SMTP.Host != "" && (*conf).SMTP.Login != "" && (*conf).SMTP.Password != "" {
+			if !((*conf).SMTP.Host == "" || (*conf).SMTP.Login == "" && (*conf).SMTP.Password == "") {
 				if err := db.Ping(); err == nil {
 					smtp_prepare(db, conf)
 				}