?
Solved

Problem sending Email from VB.NET application

Posted on 2009-04-27
5
Medium Priority
?
533 Views
Last Modified: 2013-11-30
Hello,

This is a problem with a simple DOT NET 2 application which sends email using system.net.mail.  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?

Thanks,

Stephen Simpson
Imports system.net.mail
 
Try
         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))
              .To.Add(recipient)
 
              .Subject = "Report for " & sLocation
              .Body = _
              "Attention: " & sContact & vbCrLf & _
              "Subject: Test " & vbCrLf & _
              "Location: " & sLocation & vbCrLf & _
              "Call Date: " & sCallDate & vbCrLf & vbCrLf & _
              sTextOfEmail
 
              .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
 
         smtpclient.Send(eMail)
 
         eMail.Dispose()
 
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: 
EMAIL, VB.NET.SMTP

Open in new window

0
Comment
Question by:elmcomputers
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 24250780
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.
0
 

Author Comment

by:elmcomputers
ID: 24279720
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
0
 
LVL 3

Accepted Solution

by:
AxleWack earned 1500 total points
ID: 24352124
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"))
       
        Try
            Dim m As System.Web.Mail.MailMessage = New Web.Mail.MailMessage
            With m
                .From = strFromAddress
                .To = strToAddress
                .Body = strMessage
                .Subject = strSubject
                .BodyFormat = MailFormat.Html
                .Attachments.Add(Attachment)

                .Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                .Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                .Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp server name or IP"
                '.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "NoReply@domain.co.za"
                '.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "654321"
                '.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            End With

            SmtpMail.Send(m)
           

        Catch ex As Exception
            bReturn = False
            ex.Message.ToString()
        End Try

        Return bReturn
   
    End Function

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

Author Comment

by:elmcomputers
ID: 24826503
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

Thanks
0
 
LVL 3

Expert Comment

by:AxleWack
ID: 24826663
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
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Pop culture is prime bait for hackers seeking to infect user’s computers and mobile devices with malicious malware. Hackers know exactly what the latest trends are online and know how to use them to their advantage.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

569 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