SMTP Outgoing mails stopped working after upgrading to version 15

Hello Community,

I recently upgraded to version 15, and I don’t recall any other changes to the server or mail server configuration, except this upgrade, and since then, no outgoing email has been processed.

On Email Quee DocType, I get this error:

    ctx.smtp_server.session.sendmail(
  File "/usr/lib/python3.10/smtplib.py", line 902, in sendmail
    (code, resp) = self.data(msg)
  File "/usr/lib/python3.10/smtplib.py", line 580, in data
    (code, msg) = self.getreply()
  File "/usr/lib/python3.10/smtplib.py", line 401, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed: "

On Error Log DocType, I get:

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/email/queue.py", line 150, in flush
    email_queue.send()
      EmailQueue = <class 'frappe.email.doctype.email_queue.email_queue.EmailQueue'>
      email_queue_batch = [{'name': 'ensldqedra', 'sender': 'Administrator <frappe@domain.com>'}]
      failed_email_queues = []
      row = {'name': 'ensldqedra', 'sender': 'Administrator <frappe@domain.com>'}
      email_queue = <EmailQueue: ensldqedra>
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 172, in send
    ctx.smtp_server.session.sendmail(
      self = <EmailQueue: ensldqedra>
      smtp_server_instance = None
      ctx = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7fc4ad7d09d0>
      message = b'Content-Type: multipart/mixed; boundary="===============8727358855180867664=="\r\nMIME-Version: 1.0\r\nMessage-Id: <171803523926.577492.17396706935238402870@app-dev.domain.com>\r\nX-Original-From: Administrator <frappe@domain.com>\r\nSubject: Mailer (#Mailer)\r\nFrom: Administrator <frappe@domain.com>\r\nTo: mailer@domain.com\r\nDate: Mon, 10 Jun 2024 16:00:40 -0000\r\nReply-To: frappe@domain.com\r\nX-Frappe-Site: https://app-dev.domain.com\r\n\r\n--===============8727358855180867664==\r\nContent-Type: multipart/alternative;\r\n boundary="===============4127022243446543108=="\r\nMIME-Version: 1.0\r\n\r\n--===============4127022243446543108==\r\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nadadad\r\n\r\n\r\n\r\nLeave this conversation: https://app-dev.domain.com/api/method/frappe.email.queue.unsubscribe?email=3D=\r\nmailer%40domain.com&doctype=3DEmail+Account&name=3DMailer&_signature=3D5929e3=\r\nb48e53664df69644c9bde0e5da6bc569a...
      recipient = <EmailQueueRecipient: ensl4keier parent=ensldqedra>
      method = None
  File "/usr/lib/python3.10/smtplib.py", line 902, in sendmail
    (code, resp) = self.data(msg)
      self = <smtplib.SMTP object at 0x7fc4a7b1df90>
      from_addr = 'Administrator <frappe@domain.com>'
      to_addrs = ['mailer@domain.com']
      msg = b'Content-Type: multipart/mixed; boundary="===============8727358855180867664=="\r\nMIME-Version: 1.0\r\nMessage-Id: <171803523926.577492.17396706935238402870@app-dev.domain.com>\r\nX-Original-From: Administrator <frappe@domain.com>\r\nSubject: Mailer (#Mailer)\r\nFrom: Administrator <frappe@domain.com>\r\nTo: mailer@domain.com\r\nDate: Mon, 10 Jun 2024 16:00:40 -0000\r\nReply-To: frappe@domain.com\r\nX-Frappe-Site: https://app-dev.domain.com\r\n\r\n--===============8727358855180867664==\r\nContent-Type: multipart/alternative;\r\n boundary="===============4127022243446543108=="\r\nMIME-Version: 1.0\r\n\r\n--===============4127022243446543108==\r\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nadadad\r\n\r\n\r\n\r\nLeave this conversation: https://app-dev.domain.com/api/method/frappe.email.queue.unsubscribe?email=3D=\r\nmailer%40domain.com&doctype=3DEmail+Account&name=3DMailer&_signature=3D5929e3=\r\nb48e53664df69644c9bde0e5da6bc569a...
      mail_options = ()
      rcpt_options = ()
      esmtp_opts = ['size=7571']
      code = 250
      resp = b'Accepted'
      senderrs = {}
      each = 'mailer@domain.com'
  File "/usr/lib/python3.10/smtplib.py", line 580, in data
    (code, msg) = self.getreply()
      self = <smtplib.SMTP object at 0x7fc4a7b1df90>
      msg = b'Content-Type: multipart/mixed; boundary="===============8727358855180867664=="\r\nMIME-Version: 1.0\r\nMessage-Id: <171803523926.577492.17396706935238402870@app-dev.domain.com>\r\nX-Original-From: Administrator <frappe@domain.com>\r\nSubject: Mailer (#Mailer)\r\nFrom: Administrator <frappe@domain.com>\r\nTo: mailer@domain.com\r\nDate: Mon, 10 Jun 2024 16:00:40 -0000\r\nReply-To: frappe@domain.com\r\nX-Frappe-Site: https://app-dev.domain.com\r\n\r\n--===============8727358855180867664==\r\nContent-Type: multipart/alternative;\r\n boundary="===============4127022243446543108=="\r\nMIME-Version: 1.0\r\n\r\n--===============4127022243446543108==\r\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nadadad\r\n\r\n\r\n\r\nLeave this conversation: https://app-dev.domain.com/api/method/frappe.email.queue.unsubscribe?email=3D=\r\nmailer%40domain.com&doctype=3DEmail+Account&name=3DMailer&_signature=3D5929e3=\r\nb48e53664df69644c9bde0e5da6bc569a...
      code = 354
      repl = b'Enter message, ending with "." on a line by itself'
      q = b'Content-Type: multipart/mixed; boundary="===============8727358855180867664=="\r\nMIME-Version: 1.0\r\nMessage-Id: <171803523926.577492.17396706935238402870@app-dev.domain.com>\r\nX-Original-From: Administrator <frappe@domain.com>\r\nSubject: Mailer (#Mailer)\r\nFrom: Administrator <frappe@domain.com>\r\nTo: mailer@domain.com\r\nDate: Mon, 10 Jun 2024 16:00:40 -0000\r\nReply-To: frappe@domain.com\r\nX-Frappe-Site: https://app-dev.domain.com\r\n\r\n--===============8727358855180867664==\r\nContent-Type: multipart/alternative;\r\n boundary="===============4127022243446543108=="\r\nMIME-Version: 1.0\r\n\r\n--===============4127022243446543108==\r\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nadadad\r\n\r\n\r\n\r\nLeave this conversation: https://app-dev.domain.com/api/method/frappe.email.queue.unsubscribe?email=3D=\r\nmailer%40domain.com&doctype=3DEmail+Account&name=3DMailer&_signature=3D5929e3=\r\nb48e53664df69644c9bde0e5da6bc569a...
  File "/usr/lib/python3.10/smtplib.py", line 401, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed: "
      self = <smtplib.SMTP object at 0x7fc4a7b1df90>
      resp = []
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out

I am 100% sure that the credentials are OK, the password is updated and correct on the Email Account DocType, and the server’s info (hostname, port) is OK on the Email Domain. If I don’t have this info correct, i.e., tried to change to random ports, it won’t connect due to a handshake or timeout issues, while with the correct port, it saves instantly.

Tried with an Python script, using the same login info, worked 100% fine instantly:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_test_email(smtp_server, port, from_email, to_email, username, password, use_tls):
    # Create MIME message
    msg = MIMEMultipart()
    msg['From'] = from_email
    msg['To'] = to_email
    msg['Subject'] = 'SMTP Test Email'
    message = 'This is a test email sent from a Python script using smtplib.'
    msg.attach(MIMEText(message, 'plain'))

    try:
        # Create SMTP session
        server = smtplib.SMTP(smtp_server, port)
        server.set_debuglevel(1)  # Enable debug output to see the communication with the server
        if use_tls:
            server.starttls()  # Secure the connection
        server.login(username, password)  # Authentication
        # Sending the email
        server.sendmail(from_email, to_email, msg.as_string())
        print("Email successfully sent!")
    except Exception as e:
        print(f"Failed to send email: {e}")
    finally:
        server.quit()  # Terminate the SMTP session

# SMTP configuration
SMTP_SERVER = 'smtp.yourserver.com'  # Replace with your SMTP server
PORT = 587  # SMTP port, for TLS usually 587
FROM_EMAIL = 'your-email@example.com'  # Replace with your email address
TO_EMAIL = 'recipient-email@example.com'  # Replace with the recipient's email address
USERNAME = 'your-smtp-username'  # Replace with your SMTP username
PASSWORD = 'your-smtp-password'  # Replace with your SMTP password
USE_TLS = True  # Set to True if your SMTP server requires TLS

send_test_email(SMTP_SERVER, PORT, FROM_EMAIL, TO_EMAIL, USERNAME, PASSWORD, USE_TLS)

What else can I try?

  • Tried on 3 sites on the same bench, self-hosted.
  • Versions:
    ERPNext: v15.23.3 (version-15)
    Frappe Framework: v15.27.0 (version-15)

Best Regards.

Hi @ahassoun

Seems you are using an invalid account for sending emails …

Thanks for the reply, the email was masked on purpose, the actual email was correct.

By the way, this line contained my logged-in user’s email, not the default outgoing email defined on Email Account. (Administrator account on my case)

Anyway it was already registered (in Email Account) with its correct password