Solved operation has timed

Posted on 2009-04-24
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 - 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("", "", 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
    LVL 39

    Expert Comment

    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?
    LVL 2

    Author Comment

    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

    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: ?
    LVL 2

    Author Comment

    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

    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

    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 69

    Assisted Solution

    by:Éric Moreau
    have you looked at
    LVL 2

    Author Comment

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now