Page 2 of 2 FirstFirst 12
Results 41 to 64 of 64

Thread: How to ping server before sending mail with smtp

  1. #41
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by Ramiel View Post
    part of the problem is solved.
    Now i have:
    1. Message box appears saying that server is not available and this is ok
    2. Problem: It does not catch exception
    What exception? If you send a ping and the server does not respond then there will be no exception, the Ping method will just return False.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #42
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by Ramiel View Post
    not at all. I don´t disagree with you completely but this application i´m making is a very simple app and there is no need to implement some code for which i don´t have need. Also one more thing is name resolution which is limited in vpn on remote locations so pc´s/servers between central location and remote locations can access to each other only by ip address but not by the name of the host
    Code:
            'here is your code basically
            Try
                If My.Computer.Network.Ping("someaddress") Then
                    smtpserver.Send(mailMessage)
                Else
    
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Exit Sub
            End Try
    
            'so what do THINK you save over this
            Try
                smtpserver.Send(mailMessage)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Exit Sub
            End Try
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #43
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    I already told you what he gets out of it - rather than the user seeing "Failure sending mail" they will see something like "Could not ping the server, check the VPN connection"
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #44

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    27

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by chris128 View Post
    I already told you what he gets out of it - rather than the user seeing "Failure sending mail" they will see something like "Could not ping the server, check the VPN connection"
    is there a way to log the exception in log file which will be in the root folder of application and user will only see this message that server is not available?

  5. #45
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    Yeah, there are hundreds of examples on the internet (and these forums) of how to write to a file so do a search. Also, you can get the folder that the application is running in by using Application.StartupPath
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #46
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    Code:
            Try
                smtpserver.Send(mailMessage)
            Catch ex As Exception
                MessageBox.Show("Could not ping the server, check the VPN connection")
                Exit Sub
            End Try
    Unless these are computer knowledgeable people does it really matter? Either you send the mail or you don't, and for most users anything more than "Success" or "Failure" is overkill.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #47
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by dbasnett View Post
    Code:
    Try
                smtpserver.Send(mailMessage)
            Catch ex As Exception
                MessageBox.Show("Could not ping the server, check the VPN connection")
                Exit Sub
            End Try
    Thats rubbish though because you are then assuming that the ONLY possible reason for that Send method throwing an exception is because the server is not online.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #48

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    27

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by chris128 View Post
    Yeah, there are hundreds of examples on the internet (and these forums) of how to write to a file so do a search. Also, you can get the folder that the application is running in by using Application.StartupPath
    thank you for help! i will try to find something what will be helpful to me. Sorry if i´m aksing dumb questions but i´m still learning vb. net

  9. #49
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by Ramiel View Post
    thank you for help! i will try to find something what will be helpful to me. Sorry if i´m aksing dumb questions but i´m still learning vb. net
    No problem, if you get really stuck with writing to file then post back but at least try doing it yourself first
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #50
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    Unless these are computer knowledgeable people does it really matter? Either you send the mail or you don't, and for most users anything more than "Success" or "Failure" is overkill. But go ahead keep fooling yourself.

    Maybe for this one user it might make sense, so long as they control all the VPN locations. But what happens if they go to some hotel and try to VPN in and the ISP for the hotel has ICMP blocked?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #51
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    But an error message is not just for the user's sake is it - if that were the case then why do we ever get anything more than "Success" or "Failure" in any program we use? the purpose of an error message is to tell you what the problem is - if the user does not understand it or know what to do with it then they call the IT department. I work in an IT department and trust me its a lot easier when a user rings up with a specific error message rather than a generic error where we then have to connect to their machine to check some log file to find out what the problem actually is.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  12. #52
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    So if you logged the relevant SMTP send exception, the one you contend will be eliminated by the ping, you wouldn't have a good idea as to what the problem was?

    SmtpException
    The connection to the SMTP server failed.

    -or-

    Authentication failed.

    -or-

    The operation timed out.


    My sister, who works for the VA, was having trouble with her system and email one day. She picked up the phone to call IT, like the error message instructed her to do, and guess what, the phones didn't work because they used VoIP. She thought it was very funny.
    Last edited by dbasnett; Jan 31st, 2010 at 01:31 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #53
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    No because that is not what you get, if I do this:
    Code:
    Try
                Dim s As New Net.Mail.SmtpClient("mail.doesnotexist.com")
                s.Send("[email protected]", "[email protected]", "jjj", "jdfo")
            Catch ex As SmtpException
                MessageBox.Show(ex.Message)
            End Try
    I get an alert saying "Failure sending mail". Now you could use ex.InnerException.Message instead but then you have got to add checking to make sure there actually is an InnerException etc and it just seems so much easier to send a ping first as its such a quick and small thing. I'm not saying that sending a ping is a good idea in all cases, I just think in this particular scenario it is not doing any harm.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  14. #54
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    You were joking, right?

    Code:
            Dim stpw As New Stopwatch
            Try
                'FYI - mail.doesnotexist.com exists
                Dim s As New Net.Mail.SmtpClient("mail.foo.bar")
                s.Send("[email protected]", "[email protected]", "jjj", "jdfo")
                Stop
            Catch ex As Net.Mail.SmtpException
                'I get an alert saying "Failure sending mail". 
                'Now you could use ex.InnerException.Message instead but then 
                'you have got to add checking to make sure 
                'there actually is an InnerException etc and 
                'it just SEEMS so much easier to send a ping first as its such
                'a QUICK and small thing.
                stpw.Start()
                If Not ex.InnerException Is Nothing Then
                    stpw.Stop()
                    Debug.WriteLine(ex.InnerException.Message)
                    stpw.Start()
                End If
                stpw.Stop()
                Debug.WriteLine(stpw.ElapsedTicks.ToString & " check inner exception")
            End Try
            stpw.Reset()
            stpw.Start()
            My.Computer.Network.Ping("mail.doesnotexist.com")
            stpw.Stop()
            Debug.WriteLine(stpw.ElapsedTicks.ToString & " ping")
    Last edited by dbasnett; Feb 1st, 2010 at 06:37 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #55
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: How to ping server before sending mail with smtp

    Blog entry for discussion:
    http://stateofidleness.com/?p=326

    i like the concept of eliminating wan icmp requests and chris, i know you have a deeper knowledge of the intricacies of the email process (as you're working on the smtp class) so I'd love for you to post as well!

  16. #56
    Lively Member
    Join Date
    Oct 2009
    Posts
    72

    Re: How to ping server before sending mail with smtp

    tagged for later reading.

  17. #57
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    I guess Post #54 is being ignored, huh.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #58
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: How to ping server before sending mail with smtp

    hard to argue with:

    Code:
    A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
    The remote name could not be resolved: 'mail.foo.bar'
    6832 check inner exception
    3709888448 ping
    
    A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
    The remote name could not be resolved: 'mail.foo.bar'
    5012 check inner exception
    2941554672 ping
    
    A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
    The remote name could not be resolved: 'mail.foo.bar'
    4844 check inner exception
    2307386879 ping
    very nice example!

  19. #59
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    I found out the hard way that mail.doesnotexist.com does exist. The code kept passing the catch??????? I received a bunch of mail not delivered messages in my inbox.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #60
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    haha it didnt exist for me... I just got good old Failure Sending Mail each time I tried to do it
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  21. #61
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to ping server before sending mail with smtp

    Oh and just because the ping takes more time does not mean it is not useful.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  22. #62
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by chris128 View Post
    haha it didnt exist for me... I just got good old Failure Sending Mail each time I tried to do it
    www.doesnotexist.com
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  23. #63
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by chris128 View Post
    Oh and just because the ping takes more time does not mean it is not useful.
    How is it useful, other than as a network admin?

    A funny thing happened on my way to a debate:

    Code:
        Dim srvrName As String = "mail.foo.bar"
        Dim smtpserver As New Net.Mail.SmtpClient(srvrName)
        Dim mailMessage As System.Net.Mail.MailMessage
        Private Sub foobar()
    
            'The argument for PING
            Try
                If My.Computer.Network.Ping(srvrName) Then
                    smtpserver.Send("[email protected]", "[email protected]", "jjj", "jdfo")
                    MessageBox.Show("Mail sent successfully")
                Else
                    MessageBox.Show("Could not ping someaddress")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                'Exit Sub
            End Try
    
            'The opposing view - the one I support
            Try
                smtpserver.Send("[email protected]", "[email protected]", "jjj", "jdfo")
                MessageBox.Show("Mail sent successfully")
            Catch ex As Exception
                If Not ex.InnerException Is Nothing Then
                    MessageBox.Show(ex.InnerException.Message)
                Else
                    MessageBox.Show("Failure sending mail")
                End If
                'Exit Sub
            End Try
    
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  24. #64
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: How to ping server before sending mail with smtp

    Quote Originally Posted by dbasnett View Post
    BTW - I just looked at your website. Very nice, short and succinct. San Antonio is a favorite of mine. I helped USAA build a SONET network on their campus, and did some major partying with some of them. Oh the stories.

    ahh very cool! My mom works at USAA. small world!
    thank you for the kind words on the site as well! still a work in progress as i'm getting used to the wordpress platform, but it's gettin' there!

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width