|
-
Jan 31st, 2010, 12:47 PM
#41
Re: How to ping server before sending mail with smtp
 Originally Posted by Ramiel
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.
-
Jan 31st, 2010, 12:53 PM
#42
Re: How to ping server before sending mail with smtp
 Originally Posted by Ramiel
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
-
Jan 31st, 2010, 12:55 PM
#43
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"
-
Jan 31st, 2010, 12:58 PM
#44
Thread Starter
Junior Member
Re: How to ping server before sending mail with smtp
 Originally Posted by chris128
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?
-
Jan 31st, 2010, 01:01 PM
#45
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
-
Jan 31st, 2010, 01:02 PM
#46
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.
-
Jan 31st, 2010, 01:03 PM
#47
Re: How to ping server before sending mail with smtp
 Originally Posted by dbasnett
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.
-
Jan 31st, 2010, 01:03 PM
#48
Thread Starter
Junior Member
Re: How to ping server before sending mail with smtp
 Originally Posted by chris128
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
-
Jan 31st, 2010, 01:05 PM
#49
Re: How to ping server before sending mail with smtp
 Originally Posted by Ramiel
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
-
Jan 31st, 2010, 01:08 PM
#50
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?
-
Jan 31st, 2010, 01:12 PM
#51
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.
-
Jan 31st, 2010, 01:22 PM
#52
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.
-
Jan 31st, 2010, 01:45 PM
#53
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.
-
Jan 31st, 2010, 02:24 PM
#54
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.
-
Jan 31st, 2010, 10:54 PM
#55
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!
-
Feb 1st, 2010, 02:15 AM
#56
Lively Member
Re: How to ping server before sending mail with smtp
tagged for later reading.
-
Feb 1st, 2010, 09:03 AM
#57
Re: How to ping server before sending mail with smtp
I guess Post #54 is being ignored, huh.
-
Feb 1st, 2010, 09:10 AM
#58
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!
-
Feb 1st, 2010, 09:16 AM
#59
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.
-
Feb 1st, 2010, 09:21 AM
#60
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
-
Feb 1st, 2010, 09:22 AM
#61
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.
-
Feb 1st, 2010, 09:29 AM
#62
Re: How to ping server before sending mail with smtp
 Originally Posted by chris128
haha it didnt exist for me... I just got good old Failure Sending Mail each time I tried to do it
www.doesnotexist.com
-
Feb 1st, 2010, 09:30 AM
#63
Re: How to ping server before sending mail with smtp
 Originally Posted by chris128
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
-
Feb 1st, 2010, 11:00 AM
#64
Re: How to ping server before sending mail with smtp
 Originally Posted by dbasnett
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|