logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
nethrelm  
#1 Posted : Friday, March 14, 2025 10:20:52 AM(UTC)
nethrelm

Rank: Advanced Member

Groups: Developers
Joined: 2/18/2019(UTC)
Posts: 37

We are still running AbleCommerce Gold, but since this appears to be an issue that would affect both Gold and AC9, I am posting it here. We have noticed issues where sometimes we get errors in the log saying "Failure Sending Email with Subject: {subject}. Inner Exception: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.". We have spoken with our server team and have determined that this is likely due to the email client not disposing after sending, so it just eventually times out. I looked at the CommerceBuilder source code and found that indeed, CommerceBuilder.Messaging.EmailClient does not call Dispose() after sending a message, or perhaps better, wrapping the local System.Net.Mail.SmtpClient variable in a using statement for automatic disposal. I have verified this in both my current CommerceBuilder 7.92 source as well as my CommerceBuilder 9.1 source (in which the EmailClient's Send method code remains unchanged from 7.92). I would suggest that perhaps the code be changed to:
Code:

        public static void Send(MailMessage mailMessage, SmtpSettings smtpSettings, bool throwOnError)
        {
            // IF SMTP NOT CONFIGURED, SKIP EMAIL SENDING
            if (string.IsNullOrEmpty(smtpSettings.Server)) return;
            try
            {
                using (SmtpClient smtpClient = new SmtpClient(smtpSettings.Server, smtpSettings.Port))
                {
                    if (smtpSettings.RequiresAuthentication)
                    {
                        smtpClient.Credentials = new System.Net.NetworkCredential(smtpSettings.UserName, smtpSettings.Password);
                    }
                    smtpClient.EnableSsl = smtpSettings.EnableSSL;

                    // SEND THE MAIL MESSAGE
                    smtpClient.Send(mailMessage);
                }
            }
            catch (Exception ex)
            {
                Logger.Write("Error sending email with subject '" + mailMessage.Subject + "'.", Logger.LogMessageType.Warn, ex);
                if (throwOnError) throw;
            }
        }


in future builds of CommerceBuilder 9.1, and if possible, a hotfix be issued for CommerceBuilder 7.92 as well for those of us still using it to resolve this issue.

For extra clarity, here is what our server team told us:

Quote:
In our logs, I see a lot of instances where your server connects to our mail server, submits a message, then sits idle without issuing a QUIT command. After 60s, our server times-out the connection and discards the message.

I've seen this happen with very old versions of .NET (prior to v4), and on newer versions where the app does not call SmtpClient.Dispose() to clean up the connection after sending. If the app tries interacting with SmtpClient after the time-out, I can see it giving the "Unable to write data to the transport connection" error.

Edited by user Friday, March 21, 2025 9:01:53 AM(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

nethrelm  
#2 Posted : Friday, March 21, 2025 9:03:23 AM(UTC)
nethrelm

Rank: Advanced Member

Groups: Developers
Joined: 2/18/2019(UTC)
Posts: 37

It's been a week, is anyone taking a look into this??
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.