system.net.mail.smtpexception operation has timed

Posted on 2009-04-24
Medium Priority
Last Modified: 2012-05-06
Hi Experts,

I've got a strange issue happening with an ASP.NET website.
Basically when sending an email  I get a system.net.mail.smtpexception - operation has timed

But if I use exactly the same code in a win app, it sends the email fine without erroring.

The code had been working for several months, the only thing that has changed is the latest windows updates...

Private Sub SendNewEmail()
        Dim oSmtpClient As SmtpClient = Nothing
        Dim strMessage As StringBuilder = Nothing
        Dim strSubject As StringBuilder = Nothing
        Dim oMailMessage As MailMessage = Nothing
            oSmtpClient = New SmtpClient("MAILSERVER")
            strSubject = New StringBuilder
            strSubject.Append("Ticket Allocation Mail - ")
            strMessage = New StringBuilder
            strMessage.Append("Ticket Number ")
            strMessage.Append(Microsoft.VisualBasic.ControlChars.CrLf & Microsoft.VisualBasic.ControlChars.CrLf & Microsoft.VisualBasic.ControlChars.CrLf & "------------------------- MESSAGE START -------------------------" & Microsoft.VisualBasic.ControlChars.CrLf & Microsoft.VisualBasic.ControlChars.CrLf)
            strMessage.Append("Customer Code: " & Microsoft.VisualBasic.ControlChars.CrLf)
            strMessage.Append("Call Subject : " & Microsoft.VisualBasic.ControlChars.CrLf)
            strMessage.Append(Microsoft.VisualBasic.ControlChars.CrLf & "Call Notes: " & Microsoft.VisualBasic.ControlChars.CrLf)
            strMessage.Append(Microsoft.VisualBasic.ControlChars.CrLf & "------------------------ MESSAGE END -------------------------" & Microsoft.VisualBasic.ControlChars.CrLf)
            oMailMessage = New MailMessage("emailFrom@email.com", "emailto@email.com", strSubject.ToString(), strMessage.ToString())
            oMailMessage.IsBodyHtml = False
            oMailMessage.Priority = MailPriority.High
            oSmtpClient.UseDefaultCredentials = False
            oSmtpClient.Credentials = New System.Net.NetworkCredential("username", "password")
        Catch ex As Exception
            Throw New Exception(" :: SendNewEmail@ EmailManager :: " + ex.Message)
            If Not IsNothing(strSubject) Then
                strSubject = Nothing
            End If
            If Not IsNothing(strMessage) Then
                strMessage = Nothing
            End If
            If Not IsNothing(oSmtpClient) Then
                oSmtpClient = Nothing
            End If
        End Try
    End Sub

Open in new window

Question by:samrose
  • 5
  • 3
LVL 39

Expert Comment

ID: 24223090
If it worked previously in a different application, then it sounds like your firewall is blocking the aspnet app from communicating over that port. Can you try with your firewall off?

Author Comment

ID: 24223118
Sorry I should have added that, I have made sure that there are no firewalls or proxys interfering (all turned off)
LVL 39

Expert Comment

ID: 24223512
Hmm, that's interesting. A few questions to make sure the basics are covered, please go through them in order:

1) Are you sure you need credentials? Can you give me the IP address of the host, or is it in your local subnet?

2) You say

oSmtpClient = New SmtpClient("MAILSERVER")
I hope you have that set to the correct address in your real code?

3) To be sure that your server can talk to the "MAILSERVER" can you try pointing telnet to it using

telnet MAILSERVER 25
4) and, if that works, can you try to follow the instructions here to send a message "by hand" to make sure everything is fine: http://www.activexperts.com/activemail/telnet/ ?
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


Author Comment

ID: 24223523
Yeah it is all working fine.

Basically I've added the following line
oSmtpClient.Timeout = 2000

then catch the timeout error, as the email is being sent (!!!) random.
LVL 39

Expert Comment

ID: 24223659
You mean the problem is solved now? Or you mean, all's fine on that computer using telnet and the problem still persists?
LVL 39

Accepted Solution

abel earned 1800 total points
ID: 24223673
Btw, in your original post you didn't use a timeout. The default timeout is 100,000, which means 100 seconds (it is milliseconds). You set it to a much smaller value, 2,000, which is 2 seconds. Are you sure you want to do that? To prevent timeouts, we use a setting of about 15,000 (15 seconds).
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 200 total points
ID: 24223876
have you looked at http://www.systemnetmail.com/

Author Comment

ID: 24312113
After several attempts at trying to figure this out, I finally persuaded our network administrator to restart the exchange server and if by magic it was working again....

Thanks to all that contributed to this, I'll give a share of points....
LVL 39

Expert Comment

ID: 24312144
glad it worked out in the end and that your net admin wanted to do the restart... magic! ;)

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question