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
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 2/18/2019(UTC) Posts: 37
|
It's been a week, is anyone taking a look into this??
|
|
|
|
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.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close