Click here to Skip to main content
       

Visual Basic

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
Questioncheck smtp connection before sending ?memberalejx9 Nov '12 - 9:02 
Hello !
i have an application in vb.net 2010 , and i'm using System.Net.Mail to send emails.
is there any way to test smtp connection , before begin to send emails .
 
Thank you !
AnswerRe: check smtp connection before sending ?mvpDave Kreskowiak9 Nov '12 - 9:52 
The only way to really test it is to try and send an email. Kind of defeats the purpose now, doesn't it?

GeneralRe: check smtp connection before sending ?memberalejx9 Nov '12 - 13:47 
thank you , but i need to check if smtp server is ready , and if not i need to display a warning to user and cancel the sending process. If is ready i can begin sending emails.
i have found this code , but doesn't work when i test with a invalid smtp server name:
 
public bool ValidSMTP(string hostName)
{
    bool valid = false;
    try
    {
        TcpClient smtpTest = new TcpClient();
        smtpTest.Connect(hostName, 25);
        if (smtpTest.Connected)
        {
            NetworkStream ns = smtpTest.GetStream();
            StreamReader sr = new StreamReader(ns);
            if (sr.ReadLine().Contains("220"))
            {
                valid = true;
            }
            smtpTest.Close();
        }
    }
    catch
    {
        throw;
    }
    return valid;
}

GeneralRe: check smtp connection before sending ?mvpDave Kreskowiak9 Nov '12 - 14:15 
If you give the Connect method an invalid hostname and port that cannot be connected, it'll throw a SocketException with the error code in it.
 
if the hostname is a real server but nothing is listening on 25, it'll throw a SocketException.
 
If the hostname is real and 25 is blocked by a firewall, you'll get a SocketException.
 
Sooo... what's with the lonely little "throw" statement? Remove that and your code will work. That is, assuming that the SMTP server is listening on port 25...
 

The problem with this code is that you're only testing the server connection, not the ability to send email. Just because the server responds to a connection request does not mean that the credentials given for the SMTP account to send an email will work.
 
That's why I said the best way to check is to actually send an email.

QuestionAllow a Desktop app to check for JavaScript errors on given URL?memberpogowolf9 Nov '12 - 6:17 
Using Vb.NET 2010
=============
I am trying to create a function that given a specific URL (like: www.foo.com/bar.htm) will return a Boolean if there are any JavaScript errors. I would LOVE it to return what those errors are as well, but I only need to have it return a yes/no if there are any.
 
I've searched high and low for any information regarding this topic and just haven't found anything about detecting if the HTML page has JavaScript errors.
 
Would anyone have any suggestions, ideas, or code that might be able to help me with this idea?
 
Thank you in advance!
-== The PogoWolf ==-

QuestionUsing large XML dataset efficientlymemberDisIsHoody7 Nov '12 - 8:16 
I currently have an XML file that contains about 115,000 codes along with addition information (description, "see also" information, etc), and is about 8.5MB in size. Unfortunately I did not create the file and cannot change it's format; must be used as is.
 
I've never worked with a file of this size. Just trying to open the file to look at the format was cause slow-down while opening and trying to scroll through it. However, for my application, I need to be able to dynamically update drop-down list with the codes (as the user starts to type in a code), as well as do search for codes.
 
I'm thinking this file is too large to load into an XDoc object or into a custom sorted list (key=code, value=description). I'm hoping someone has had experience working with similarly large XML files and has some suggestions on the most efficient way to work with a file like this.
 
Thanks in advanced for any help you can provide.
AnswerRe: Using large XML dataset efficientlymemberDavid Mujica7 Nov '12 - 9:10 
How about this ...
 
1) Load the data into a SQL server table.
2) Have your application access and manipulate the data in the database.
3) Whenever you need the file, then run a routine to export the data from the database to the XML file.
 
Just a thought.
Cool | :cool:
Questionvb.net Web Browser Control! how to automate when web page is using frames.memberKieran Sloan7 Nov '12 - 4:27 
A web page I'm trying to automate has come to my attention that it using frames. the source is and link to page is below:
 
url: http://www.konaeuropeadmin.com/[^]
 
My code so far...
 
Dim theElementCollection As HtmlElementCollection = KonaBrwsr.Document.GetElementsByTagName("input")
 
        For Each curElement As HtmlElement In theElementCollection
 
            Dim controlName As String = curElement.GetAttribute("name")
 
            If controlName = "loginname" Then
                curElement.SetAttribute("Value", "username")
            End If
 
            If controlName = "loginpassword" Then
                curElement.SetAttribute("Value", "password")
            End If
 
            If controlName = "savepassword" Then
                curElement.SetAttribute("Value", "True")
            End If
 
        Next
 
        Dim theElementCollection2 As HtmlElementCollection = KonaBrwsr.Document.GetElementsByTagName("input")
 
        For Each curElement2 As HtmlElement In theElementCollection2
 
            Dim controlName2 As String = curElement2.GetAttribute("name").ToString
 
            If controlName2 = "login" Then
                curElement2.InvokeMember("Click")
            End If
 
        Next
 

I know this works as I've used the same procedure for all the webpages I'm trying to automate... 15 in total; downloading files automatically.
 
The problem with this site is that it uses frames, and although I know my code work for a simple HTML form, I have no idea how to repeat this procedure for a framed website.
 
Someone please help, I've been on this for a while now and simply not working for me.
 
Thank you all in advance.
AnswerRe: vb.net Web Browser Control! how to automate when web page is using frames.memberZaf Khan26 Nov '12 - 2:13 
Inside the page (in your link) you will find the following code.......
 
<html>
<head>
<title>Kona Europe</title>
<frameset rows="92,*">
    <frame name="enterpart" scrolling="no" noresize>
    <frameset cols="310,*">
        <frame name="treeframe" src="http://www.konaeuropeadmin.com/getcountry.htm">
        <frame name="basefrm" src="http://www.konaeuropeadmin.com/website/rightframe.htm">
    </frameset>
    <noframes>
        <body>
        <p>This page uses frames, but your browser doesn't support them.</p>
        </body>
    </noframes>
</frameset>
</html>
 

in THAT page (the page in your link - or even ANY other page you wish)
 

first assess if the FRAME or IFRAME tag is present and if it is then load the SRC file that the individual FRAME SRC points to and then run your code for EACH frame and treat each frame as a separate html document.
 
If the fields your looking for are there then your code will do what its supposed to and if not then your code shouldnt do anything and you simply continue to the next frame.
 
If theres NO frames then your code will operate as normal....
 
See the pseudo code below
 
'1   Get the ORIGINAL document
'2     look for the FRAME tag (if no frame tags jump to step 10)
'3       in the frame tag look for the SRC attribute/element
'4         load the document using the SRC as the file to load pointer
'5           == YOUR CODE HERE ==
'6         we are done with this document 
'7       we are done with this frame
'8     move to the next frame (and repeat till no more frames)
'9   All done - jump to step 12
'10  == YOUR CODE HERE ==
'11  All done  - jump to step 12
'12  Finished

QuestionHelp with Error MessagememberGeorgieMPorgie5 Nov '12 - 3:32 
I currently have an array populated with string values and am trying to compare the values in the array to other string values, but I am getting an error. The error message is “Conversion from string "SDrug" to type 'Boolean' is not valid”. Here is the code I have written.

“If IndustrySectorContentArray(IndustrySectorCounter) = "SFinancials" Or "SDrug" Then “.
 
If I just compare the content in the array to "SFinancials" then I don’t have an issue, but when I add the “Or” command I am getting the error.
 
Can someone point me in the right direction to get the desired result?
 
Thanks.
George

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 21 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid