BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
optimized email sending. fixed maillog event handler cannot catch the timer event.
Jack71be2144083a
diff --git a/core/internal/service/mail_boxes/mail_boxes.go b/core/internal/service/mail_boxes/mail_boxes.goindex 33cf919c..f01427ac 100644--- a/core/internal/service/mail_boxes/mail_boxes.go+++ b/core/internal/service/mail_boxes/mail_boxes.go@@ -84,6 +84,16 @@ func Get(ctx context.Context, domain, keyword string, page, pageSize int) ([]v1.return mailboxes, count, err}+func PasswordByEmail(ctx context.Context, email string) (pwd string, err error) {+ val, err := g.DB().Model("mailbox").Where("username", email).Value("password_encode")++ if err != nil {+ return+ }++ return PasswdDecode(ctx, val.String())+}+func PasswdEncode(ctx context.Context, password string) string {return hex.EncodeToString([]byte(base64.StdEncoding.EncodeToString([]byte(password))))}diff --git a/core/internal/service/mail_service/sending.go b/core/internal/service/mail_service/sending.goindex 9822b92e..6426ba9f 100644--- a/core/internal/service/mail_service/sending.go+++ b/core/internal/service/mail_service/sending.go@@ -1,10 +1,12 @@package mail_serviceimport (+ "billionmail-core/internal/service/mail_boxes""billionmail-core/internal/service/public""context""crypto/tls""encoding/hex"+ "errors""fmt""github.com/gogf/gf/util/grand""github.com/gogf/gf/v2/frame/g"@@ -48,10 +50,10 @@ func NewMessage(title string, content string) Message {}type EmailSender struct {- Email string `json:"email"` // email of sender- Host string `json:"host"` // SMTP server address- Port string `json:"port"` // SMTP server port- Password string `json:"password"` // SMTP password+ Email string `json:"email" v:"required|email"` // email of sender+ Host string `json:"host" v:"required|domain"` // SMTP server address+ Port string `json:"port" v:"required"` // SMTP server port+ Password string `json:"password" v:"required"` // SMTP passwordclient *smtp.Client // persistent SMTP client connectionmutex sync.Mutex // mutex for thread safetyconnected bool // connection status@@ -71,6 +73,24 @@ func NewEmailSender() *EmailSender {return e}+func NewEmailSenderWithLocal(email string) (es *EmailSender, err error) {+ es = NewEmailSender()++ es.Email = email+ es.Password, err = mail_boxes.PasswordByEmail(context.Background(), email)++ if err != nil {+ return+ }++ if !es.IsConfigured() {+ err = errors.New("Email Sender not configured")+ return+ }++ return+}+// Close closes the SMTP connectionfunc (e *EmailSender) Close() {_ = e.Disconnect()diff --git a/core/internal/service/maillog_stat/maillog_stat.go b/core/internal/service/maillog_stat/maillog_stat.goindex 76cc4653..39957668 100644--- a/core/internal/service/maillog_stat/maillog_stat.go+++ b/core/internal/service/maillog_stat/maillog_stat.go@@ -790,21 +790,22 @@ func NewMallogEventHandler(maillogPath string, delay time.Duration) *MallogEvent// Start starts the mail log event handlerfunc (handler *MallogEventHandler) Start() {_, err := gfsnotify.Add(handler.maillogStat.maillogPath, func(event *gfsnotify.Event) {- g.Log().Debug(context.Background(), "MallogEventHandler: catch event", event)+ // g.Log().Debug(context.Background(), "MallogEventHandler: catch event", event)if event.IsWrite() {- g.Log().Debug(context.Background(), "MallogEventHandler: write event", event)+ // g.Log().Debug(context.Background(), "MallogEventHandler: write event", event)if event.Path == handler.maillogStat.maillogPath {- if !handler.timer.Stop() {- <-handler.timer.C- }+ g.Log().Debug(context.Background(), "Reset timer", event)+ //if !handler.timer.Stop() {+ // <-handler.timer.C+ //}handler.timer.Reset(handler.delay)}}- if event.IsRename() {- g.Log().Debug(context.Background(), "MallogEventHandler: rename event", event)- }+ //if event.IsRename() {+ // g.Log().Debug(context.Background(), "MallogEventHandler: rename event", event)+ //}})if err != nil {