Problem sending Email from VB.NET application

Posted on 2009-04-27
Last Modified: 2013-11-30

This is a problem with a simple DOT NET 2 application which sends email using  The email has a small PDF attachment.

It works fine here at my office on my notebook with a nuber of SMTP servers and two different ISP's.

However at the client's site (I change the SMTP server/port to the one they need to use), the email function hangs the application with no error trapped.    In the meantime while I am waiting I cannot end the process even if I use task manager.  i have to restart the computer.

I can ping the mail server and get the three expected replies.

At a command prompt I can use telnet to send an email.

I am not sure where to begin to diagnose the problem.   It is on a large corporate network and I cannot hook my notebook into it and they are locked down so I cannot install another email client to test.    

I have tried lowering the timeout value on the smtpclient and it made no difference.

Any Ideas?


Stephen Simpson



         Dim eMail As New MailMessage

         With eMail


              .From = New System.Net.Mail.MailAddress(sEmailReplyTo)


              Dim recipient As System.Net.Mail.MailAddress = New System.Net.Mail.MailAddress(Trim(sEmail))



              .Subject = "Report for " & sLocation

              .Body = _

              "Attention: " & sContact & vbCrLf & _

              "Subject: Test " & vbCrLf & _

              "Location: " & sLocation & vbCrLf & _

              "Call Date: " & sCallDate & vbCrLf & vbCrLf & _



              .Attachments.Add(New Net.Mail.Attachment(di.FullName & "\" & Trim(sAttach)))


               .IsBodyHtml = False

          End With


         Dim smtpclient As New System.Net.Mail.SmtpClient

         smtpclient.Host = sSMTPServer 

         smtpclient.Port = sSMTPPort '1025


         If sSMTPUser <> "" Then

                smtpclient.Credentials = New System.Net.NetworkCredential(sSMTPUser, sSMTPPassword)  

         End If






Catch exEmail As Exception                    

           DisplayStatus("Email processing failed while processing:" & vbCrLf & sTrans & vbCrLf & exEmail.Message, True)

End Try 

Open in New Window Select All Tags: 


Open in new window

Question by:elmcomputers
    LVL 21

    Expert Comment

    It could be client antivirus software blocking programs from sending email - maybe try it with antivirus momentarily disabled.  Another thought would be check the windows event logs in case there's some security failure being logged, or maybe trouble resolving the smtp server.

    Author Comment

    THanks for you comment.  I will work on this.  The problem is that this is on a large corporate LAN and i have limited access to settings and the control panel.  I do not expect that I will be able to disable the anti virus for a test
    LVL 3

    Accepted Solution

    You must check that the server you are running to(smtp server) isnt blocking anything. I sat with the exact same error. I thought it was on my side, but later found out that it was the smtp server I was using, it was blocking my email sending requests.

    Here is the code I used, if you are interested.

    Public Function SendEmail(ByVal strMessage As String, _
                                 ByVal strToAddress As String, _
                                 ByVal strFromAddress As String, _
                                 ByVal strSubject As String) As Boolean

            Dim bReturn As Boolean = True
            Dim attachment As New MailAttachment(Server.MapPath("Attachments\Filename.pdf"))
                Dim m As System.Web.Mail.MailMessage = New Web.Mail.MailMessage
                With m
                    .From = strFromAddress
                    .To = strToAddress
                    .Body = strMessage
                    .Subject = strSubject
                    .BodyFormat = MailFormat.Html

                    .Fields.Item("") = 2
                    .Fields.Item("") = 25
                    .Fields.Item("") = "smtp server name or IP"
                    '.Fields.Item("") = ""
                    '.Fields.Item("") = "654321"
                    '.Fields.Item("") = 1
                End With


            Catch ex As Exception
                bReturn = False
            End Try

            Return bReturn
        End Function

     Protected Sub btnEmailTo_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     End Sub

    Author Comment

    I called up the tech support department of the company that owned the network and described the problem that I was having.

    A couple of days later the software, without modification just started to work properly.  I assume that the support team had some setting wrong, but I guess I will never know what it was

    LVL 3

    Expert Comment

    I had the same issue a while ago... I believe it was something to do with their settings allowing mails to go out or to do with their SMTP setting on their server from where emails are being sent from.

    Glad its working atleast

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 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

    17 Experts available now in Live!

    Get 1:1 Help Now