Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, I got a windows service that sends 234 emails to administrator as notification every 03:00 EST. This is working fine for years. But suddenly I got a 102 emails error from EmailAutoResendServicesaying:

Email Auto Resending service encountered an error in Actual resending of email from 'SystemName'.
Email ID: 1777

System.InvalidCastException: Conversion from string "" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) at WS_EmailAutoResend_V2.EmailResendingLib.getEmailLogRecords()
This is a system generated email, please do not reply.


And upon checking to the System's email log, it got 102 unsuccessfully sent email containing an error message:

System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: 4.3.2 The maximum number of concurrent connections has exceeded a limit, closing transmission channel
   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at SystemName_Notification.BLL.FnSendEmail(String strTo, String strToName, String strCC, String strBCC, String strSubject, String strMsg)



I would like to ask if what does trigger that error message. How could this happen if it is working fine. Until today, it is working fine. It is just occur on that particular day and time.

What I have tried:

***No solution for this yet ***
Posted
Updated 7-Jun-17 23:15pm
Comments
F-ES Sitecore 8-Jun-17 4:38am    
Your code is trying to parse a number (int or double) from a string and the string it is being given can't be parsed as a number. As for your second error your code should be robust enough to handle these exceptions and re-try later on.
Aifos Lavigne 8-Jun-17 4:49am    
I see. Do you think it is a code error? or exchange server and internal settings? I can't figure out the problem because the email saying that there is error between parameters but upon checking the error log, it looks like a server settings.
Afzaal Ahmad Zeeshan 8-Jun-17 4:53am    
First one is the code error. You should write an appropriate check to see if the string is fine or not. I have shown a code sample that does that.

Secondly, the second one is much more of an IT error, where your servers (or their servers, since you didn't mention anything about that) are not functioning to their maximum or the users are highly interested in a service at this hour.

In any circumstance, what you need to do is modify the servers to enable more connections (there are several ways in which you can do that).
Afzaal Ahmad Zeeshan 8-Jun-17 4:55am    
Never mind

F-ES Sitecore nailed it down but I will try to explain in more detail.

An exception occured in the code of your Windows service in the function ToInteger() called within WS_EmailAutoResend_V2.EmailResendingLib.getEmailLogRecords(). The exception is thrown because the string to be parsed is empty (Conversion from string "" to type 'Integer' is not valid.).

Due to the exception the thread executing the code to send a mail is terminated while the service itself still runs. But the thread has opened an SMTP connection which is left in stale state. Because you are trying to send multiple mails and some fail with that exception you will have multiple dead SMTP connections until the limit of concurrent connections is reached. Then sending the next mail fails when trying to open an SMTP connection.

So the second error is sourced by multiple occurences of the first error. And you will not see the first error anymore because the second one occurs before parsing the integer string.

To find out what happened you have to inspect the code and how it is called. Because it was working in the past it should be not too difficult to find out which string containing an integer is empty now. If it was happening on a specific day only, you might start witch checking what was special on that day.

To avoid the second error in the future the code should catch exceptions and then close the SMTP connection (and all other kind of open handles like files).

To avoid the first error catch also exceptions or better check parameters for validity and generate an additional error mail or add the information about the invalid parameter to the mail itself.
 
Share this answer
 
Both the errors are pretty much clear and neat in their sense,
Quote:
Conversion from string "" to type 'Integer' is not valid
How can you convert an empty string to an integer? It should at least be a "0", or something similar. There is a safe way to parse the string to integers,
C#
int number;
if(int.TryParse(your_value, out number) {
    // Continue with the rest of the code
} else {
    // Break; integer is not valid string; or other way around :D
}

As already mentioned, the problem is that the server cannot take more connections as already enough clients have been connected. There are two ways to solve this:
1. Reattempt to connect, which would again (more likely) result in the same problem.
2. Tell the user that the server is not responding. Which won't be a good approach for UX.

Somehow, since you say that this was working then you need to wait or retry again later, their server might be expecting a load of users.

Also, you should check up against their subscriptions information to know why are they showing this error, an email service should not be down, if you are paying them for the service. If in the case of a trial, then it should be fine and you should understand this. :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900