From 200f464925dcebd8e22b078d50c460fd28e3a115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=92=E9=87=8E=E7=84=A1=E7=87=88?= Date: Mon, 13 Apr 2020 20:15:08 +0800 Subject: [PATCH] smtp buildMessage(): flush quotedprintable writer buff explicitly --- backend/app/notify/email.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/app/notify/email.go b/backend/app/notify/email.go index 3edc36dd..f9800947 100644 --- a/backend/app/notify/email.go +++ b/backend/app/notify/email.go @@ -371,7 +371,10 @@ func (e *Email) buildMessage(subject, body, to, contentType, unsubscribeLink str if _, err := qp.Write([]byte(body)); err != nil { return "", err } - defer qp.Close() + // flush now, must NOT use defer, for small body, defer may cause buff.String() got empty body + if err := qp.Close(); err != nil { + return "", fmt.Errorf("quotedprintable Write failed: %w", err) + } m := buff.String() message += "\n" + m return message, nil