Sending an email sometimes fails

Hi,
we are seeing issues when sending emails using SmtpClient class. 99% of emails are sent without issues, but sometimes, an email will not be sent and we don’t get an error in this case (SmtpClient::send does not throw an exception). At the moment, it seems, this only happens on Linux systems.

I enabled logging to get more information. A successful send looks like this:

Smtp client[1|29.10.2024 12:59:35]:
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: Bind Address: IPv4: /83.169.7.135 :53152
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: Remote Address: IPv4: wp1013335.mailout.server-he.de/5.175.14.203 :465
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 220 wp681.webpack.hosteurope.de ESMTP Host Europe Mail Service Tue, 29 Oct 2024 12:59:35 +0100
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: EHLO lvps83-169-7-135.dedicated.hosteurope.de
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 250-wp681.webpack.hosteurope.de Hello lvps83-169-7-135.dedicated.hosteurope.de [83.169.7.135]
Smtp server[1|29.10.2024 12:59:35]: 250-SIZE 52428800
Smtp server[1|29.10.2024 12:59:35]: 250-8BITMIME
Smtp server[1|29.10.2024 12:59:35]: 250-PIPELINING
Smtp server[1|29.10.2024 12:59:35]: 250-AUTH PLAIN LOGIN
Smtp server[1|29.10.2024 12:59:35]: 250 HELP
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: AUTH PLAIN xxx=
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 235 Authentication succeeded
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: NOOP
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 250 OK
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: MAIL FROM:
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: RCPT TO:
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: RCPT TO:
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: DATA
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 250 OK
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 250 Accepted
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 250 Accepted
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 354 Enter message, ending with “.” on a line by itself
Smtp server[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: Content-Type: text/html; charset=“Windows-1252”
Smtp client[1|29.10.2024 12:59:35]: Date: Tue, 29 Oct 2024 11:59:35 +0000

Smtp client[1|29.10.2024 12:59:35]:
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]: .
29.10.2024 12:59:35

Smtp client[1|29.10.2024 12:59:35]:
Smtp client[1|29.10.2024 12:59:35]:
29.10.2024 12:59:35

Smtp server[1|29.10.2024 12:59:35]: 250 OK id=1t5ksp-0007Yo-6W
Smtp server[1|29.10.2024 12:59:35]:

In this log, you can see that the SMTP Server finishes the conversation with 250 OK …

When a send fails, that part is missing:


Smtp client[1|29.10.2024 13:22:10]: Bind Address: IPv4: /83.169.7.135 :48538
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: Remote Address: IPv4: wp1013335.mailout.server-he.de/5.175.14.203 :465
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 220 wp681.webpack.hosteurope.de ESMTP Host Europe Mail Service Tue, 29 Oct 2024 13:22:10 +0100
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: EHLO lvps83-169-7-135.dedicated.hosteurope.de
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 250-wp681.webpack.hosteurope.de Hello lvps83-169-7-135.dedicated.hosteurope.de [83.169.7.135]
Smtp server[1|29.10.2024 13:22:10]: 250-SIZE 52428800
Smtp server[1|29.10.2024 13:22:10]: 250-8BITMIME
Smtp server[1|29.10.2024 13:22:10]: 250-PIPELINING
Smtp server[1|29.10.2024 13:22:10]: 250-AUTH PLAIN LOGIN
Smtp server[1|29.10.2024 13:22:10]: 250 HELP
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: AUTH PLAIN xxx=
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 235 Authentication succeeded
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: NOOP
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 250 OK
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: MAIL FROM:
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: RCPT TO:
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: RCPT TO:
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: DATA
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 250 OK
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 250 Accepted
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 250 Accepted
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp server[1|29.10.2024 13:22:10]: 354 Enter message, ending with “.” on a line by itself
Smtp server[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: Content-Type: text/html; charset=“Windows-1252”
Smtp client[1|29.10.2024 13:22:10]: Date: Tue, 29 Oct 2024 12:22:10 +0000

Smtp client[1|29.10.2024 13:22:10]:
Smtp client[1|29.10.2024 13:22:10]:
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]: .
29.10.2024 13:22:10

Smtp client[1|29.10.2024 13:22:10]:
Smtp client[1|29.10.2024 13:22:10]:

Here, the SMTP Server does not reply to the last line; we’ve seen other cases, where the “. on a line by itself” is also not in the log.

This happens with different email providers. We tried to talk to our provider to get some help analyzing this issue (because it seems there is a normal conversation happening between Aspose and SMTP server), but unfortunately they are of no help.

As it’s not happening all the time, it’s hard to create a test case for this issue. Do you have any idea, what could be causing this issue or any hint for further analysis?

Kind regards,
Arne

@arne411

It seems you are experiencing intermittent issues with the SmtpClient class when sending emails, particularly on Linux systems. Given that 99% of your emails are sent successfully, but some fail without any error messages, this can be quite frustrating.

Here are a few suggestions to help you troubleshoot and analyze the issue further:

  1. Check Network Stability: Since the issue occurs sporadically, it might be related to network instability. Ensure that your network connection is stable and that there are no interruptions during the email sending process.

  2. SMTP Server Configuration: Verify the configuration of your SMTP server. Sometimes, server settings can lead to dropped connections or timeouts, especially under certain conditions. Ensure that the server is configured to handle the volume of emails you are sending.

  3. Logging and Debugging: You mentioned that you have enabled logging. Continue to monitor the logs for any patterns or specific conditions under which the failures occur. Look for any discrepancies in the logs when the emails fail to send, such as timeouts or connection resets.

  4. Asynchronous Sending: If you are using synchronous methods to send emails, consider switching to asynchronous methods. This can help prevent blocking and may provide better error handling. The asynchronous approach allows your application to continue running while waiting for the email to be sent.

  5. Email Size and Content: Check if the size or content of the emails being sent could be causing issues. Some SMTP servers have limits on the size of emails or specific content types that may trigger filtering or blocking.

  6. Testing with Different Providers: Since you mentioned that the issue occurs with different email providers, try testing with a different SMTP server to see if the problem persists. This can help isolate whether the issue is with your application or the SMTP server.

  7. Error Handling: Implement robust error handling in your code to catch any exceptions that may not be thrown by the SmtpClient class. This can help you identify issues that may not be immediately apparent.

If the problem continues, consider reaching out to your email service provider for further assistance, as they may have insights into server-side issues that could be affecting email delivery.

I hope these suggestions help you identify and resolve the issue. If you have any further questions or need additional assistance, feel free to ask!

Hello @arne411,

We can mock up your workflow and stress-test it on a Linux system.
How is the email sending process organized?
Please describe the message sending load. What is the average number of messages sent to how many servers?

Hi @sergey.vivsiuk
our application has a workflow similar to a regular MTA like Thunderbird. So the application does not send lots of emails. Sending is always initiated by a user - they compose mails and when done they send them.
Typically customers have multiple email adresses hosted by a single provider (e.g. hosted by Gmail, Microsoft and others), so their emails will be sent to their providers smtp server.
When analyzing the issue, we ran manual tests in our application - we typically sent 10 emails (always same sender, always same recipient) and most of the time, at least one email fails. Size of the message does not matter, for testing we sent messages with only 1 or 2kb in size. For our customers, I’d estimate that sending 1 or 2 emails per minute would be the maximum (but then of course to different recipients).

Let me know, if you need more information.

@arne411,

Thank you for the information. We are working to resolve the issue.

@arne411
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): EMAILJAVA-35324

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.