Browse Source

If POSTFIX_SUBMISSION_TLS, use port 587

Son NK 5 years ago
parent
commit
b15eeb10c5
2 changed files with 14 additions and 4 deletions
  1. 7 3
      app/email_utils.py
  2. 7 1
      email_handler.py

+ 7 - 3
app/email_utils.py

@@ -22,6 +22,7 @@ from app.config import (
     DKIM_HEADERS,
     ALIAS_DOMAINS,
     SUPPORT_NAME,
+    POSTFIX_SUBMISSION_TLS,
 )
 from app.log import LOG
 from app.models import Mailbox, User
@@ -174,7 +175,7 @@ def send_cannot_create_domain_alias(user, alias, domain):
 
 
 def send_email(
-    to_email, subject, plaintext, html, bounced_email: Optional[Message] = None
+    to_email, subject, plaintext, html=None, bounced_email: Optional[Message] = None
 ):
     if NOT_SEND_EMAIL:
         LOG.d(
@@ -187,8 +188,11 @@ def send_email(
 
     LOG.d("send email to %s, subject %s", to_email, subject)
 
-    # host IP, setup via Docker network
-    smtp = SMTP(POSTFIX_SERVER, 25)
+    if POSTFIX_SUBMISSION_TLS:
+        smtp = SMTP(POSTFIX_SERVER, 587)
+        smtp.starttls()
+    else:
+        smtp = SMTP(POSTFIX_SERVER, 25)
 
     if bounced_email:
         msg = MIMEMultipart("mixed")

+ 7 - 1
email_handler.py

@@ -46,6 +46,7 @@ from app.config import (
     ALIAS_DOMAINS,
     ADMIN_EMAIL,
     SUPPORT_EMAIL,
+    POSTFIX_SUBMISSION_TLS,
 )
 from app.email_utils import (
     get_email_name,
@@ -525,7 +526,12 @@ class MailHandler:
         LOG.debug("Rcpt to %s", envelope.rcpt_tos)
         message_data = envelope.content.decode("utf8", errors="replace")
 
-        smtp = SMTP(POSTFIX_SERVER, 25)
+        if POSTFIX_SUBMISSION_TLS:
+            smtp = SMTP(POSTFIX_SERVER, 587)
+            smtp.starttls()
+        else:
+            smtp = SMTP(POSTFIX_SERVER, 25)
+
         msg = Parser(policy=SMTPUTF8).parsestr(message_data)
 
         for rcpt_to in envelope.rcpt_tos: