Wednesday, August 15, 2007

Checking Yahoo! Account via HTTP

Download Source (10 kb)

Introduction

As we all know Yahoo has stopped POP3 access to its free email service. This article will explain you how to check HTTP based email account from a Visual Basic Application. This article is just a head-start to developing a framework for a full-fledged application which can be customized for similar HTTP based email accounts. Being it HTTP your program is guaranteed to work regardless of the type of internet connection you have.

 

The Concept and method

The concept is fairly simple. Something that we do all the time, but never think of achieving in the manner I am about to show. How do all of us check our Yahoo! Accounts? These are the steps we follow:

 

  1. Connect to the mail.yahoo.com website.
  2. Key in our login and password.
  3. Hit the "login" button.

 

After which, the traditional Yahoo! Mailbox page shows up.

 

Now let us try doing the same programmatically:

 

  1. Load the mail.yahoo.com website in one of our nested Internet Explorer Controls.
  2. Set the Login name and Password fields to our login/password combination.
  3. Invoke the "Submit" method of the form.

 

Simple! Isn't it? Now, after following the above steps, the browser automatically loads up the Yahoo! Mailbox page. All that we have to do now is parse the HTML page correctly and extract the required information.

 

The YahooMailChecker Application

Let us call our application the YahooMailChecker Application. This is going to be a standard Windows Application (EXE) Project in Microsoft Visual Basic 6.0.

 

Our application will require the following references:

 

  1. Microsoft HTML Object library.
  2. Microsoft Internet Explorer.

 

Our applications will host the following controls:

 

  1. Timer control
  2. Status bar control.

 

We will require the timer control because we will be checking our Yahoo! Account at a periodic interval. And obviously the status bar will keep telling us what exactly the Internet Explorer is up to.

 

 

Connecting to the Yahoo! Mail site

As you must have guessed by now, the entire code will go inside the Timer controls, Timer event. I have set the interval of the timer control to 15 seconds, you will have to adjust this interval based on the speed of the internet connection you have.

 

Here is how our application will work:

 

  1. Create an instance of the Internet Explorer object and set it to our global variable.
  2. Start work inside the Timer controls event.

 

The Internet Explorer Object which we will use has an event called DocumentComplete, we will be using this event to get notified of the browser's completion status. Inside this event, we will check if we have already being authenticated on the yahoo mail site or not. If yes, go ahead and extract the required information. If not, try logging in.

 

In order to connect to the Yahoo! Mail site you will be using the Navigate method of the Internet Explorer object.

 

Here's the code snippet from the Timer control's Timer event:

Private Sub tmrWorkerThread_Timer()
    Dim FirstPart As String
    Dim OpenBracket As Integer
    Dim CloseBracket As Integer
    Dim Actual As String

    tmrWorkerThread.Enabled = False

    sbYMC.Panels(1).Text = "Navigating"

    YahooMail.navigate " http://mail.yahoo.com"

    Do While YahooMail.readyState <> READYSTATE_COMPLETE
        DoEvents
        sbYMC.Panels(1).Text = YahooMail.StatusText
    Loop

    If InStr(YahooMail.document.body.innerHTML, "You must sign in to read or send mail") <> 0 Or InStr(YahooMail.document.body.innerHTML, "Invalid Password") <> 0 Then
        With YahooMail.document
            .All.Item("login").Value = "myloginid"
             .All.Item("passwd").Value = "mypassword"
            .Forms(0).submit
        End With

        Do While YahooMail.readyState <> READYSTATE_COMPLETE
            DoEvents
            sbYMC.Panels(1).Text = YahooMail.StatusText
        Loop
    Else
        lblMailBoxState = "Authenticated"
    End If

    tmrWorkerThread.Enabled = True
End Sub

 

Let us try and understand the above code now. The above code works in the following manner:

 

  1. Navigate to the mail.yahoo.com site by calling the Navigate method of the Internet Explorer object. I have called my Internet Explorer " YahooMail ".
  2. Wait till the page loading is complete. This is achieved by waiting for the Browser's completion status (READYSTATE_COMPLETE).
  3. Once the page is loaded check the HTML content to see if you have already logged in using some different session i.d. (yahoo maintains this in the form of cookies on the client's machine). This check is made by checking for the "You must sign in to read or send mail" text inside the HTML content (InnerHTML). If this text is not found that means the browser is using an existing cookie (which had worked in the past).

That's it!

 

The DocumentComplete event

Now that the page has loaded in our browser object, we need to extract the relevant information. This is done inside the DocumentComplete event of the Internet Explorer object.

 

Here is how the code inside this event looks like:

 

Private Sub YahooMail_DocumentComplete(ByVal pDisp As Object, URL As Variant)

    If InStr(YahooMail.document.body.innerHTML, ">Inbox") > 0 Then

        FirstPart = Mid(YahooMail.document.body.innerHTML, InStr(YahooMail.document.body.innerHTML, ">Inbox"), 20)

       

        OpenBracket = InStr(FirstPart, "(")

        CloseBracket = InStr(FirstPart, ")")

       

        If OpenBracket = 0 Or CloseBracket = 0 Then

            lblInboxCount = "No Unread Mails"

        Else

            Actual = Mid(FirstPart, OpenBracket + 1, CloseBracket - OpenBracket - 1)

           

            lblInboxCount = Actual

        End If

    

        FirstPart = Mid(YahooMail.document.body.innerHTML, InStr(YahooMail.document.body.innerHTML, ">Bulk"), 20)

       

        OpenBracket = InStr(FirstPart, "(")

        CloseBracket = InStr(FirstPart, ")")

       

        If OpenBracket = 0 Or CloseBracket = 0 Then

            lblInboxCount = "No Unread Bulk Mails"

        Else

            Actual = Mid(FirstPart, OpenBracket + 1, CloseBracket - OpenBracket - 1)

       

            lblBulkCount = Actual

        End If

    End If

End Sub

 

Let us now understand how this code works:

 

  1. If the target document contains the following text : ">Inbox" it means that you have logged into the account.
  2. Go ahead and hunt for the location of the above text.
  3. Extract the Unread mail count and then repeat the steps for the Bulk Mail folder.

Simple wasn't it? That's how simple it is! We just think all these things are complicated and miss out the real fun.

Tuesday, August 14, 2007

Pocket Hosts v1.5


Pocket Hosts v1.5
 
Summary: Pocket Hosts allows you to edit the static host name to IP address mappings on a Pocket PC. This is the handheld equivalent of writing a HOSTS file on your desktop PC. Also includes versions for Handheld PC 2000 devices and X86 emulation environments...

Requirements:
  • Pocket PC

 
» Pocket Hosts v1.5 Description

Pocket Hosts allows you to edit the static host name to IP address mappings on a Pocket PC. This is the handheld equivalent of writing a HOSTS file on your desktop PC. Also includes versions for Handheld PC 2000 devices and X86 emulation environments


Download
the Pocket Hosts v1.5 free for Pocket PC (146 KB)
Made by: Developer e-mail

Network Troubleshooting FAQ

Introduction

So you've decided to connect your Handheld PC or Pocket PC to your network via Ethernet or 802.11b or Proxim and you can't get connected.  This FAQ covers common troubleshooting tips for network connections.  Note:  The Pocket PC and Windows CE does not provide some of the common tools for configuring and diagnosing network problems such as arp, finger, hosts, traceroute, etc.  You can find a list of these applications on the Network Utilities FAQ.

Troubleshooting Tips

  1. Connect with ActiveSync to your desktop using your serial or USB connection. You can not sync with a desktop that you have never connected to.
  2. Install VxUtil from www.cam.com using your serial or USB connection.  It installs common TCP/IP utilities like Ping which will allow you to diagnose network connections.
  3. Connect your Handheld PC or Pocket PC to your network. Look at the hub lights and confirm that you have a link.  If you are using wireless then check the signal strength of the wireless LAN on the Pocket PC and that the access point sees the Pocket PC.  See the 802.11 Wireless LAN Configuration FAQ for details on the settings that you should check.
  4. See what IP address is assigned to your Handheld PC or Pocket PC. If you are using DHCP and no IP address is assigned, you need to assign a static IP address. Contact your network administrator for assistance with this.  Also, make sure that your gateway is set.  If it is not then you will not be able to access other networks, including the internet.
  5. Don't forget to remove and reinsert the card to make the Handheld PC or Pocket PC's TCP/IP settings take effect.
  6. Attempt to ping your desktop by IP address. If this fails, check the cables or driver settings.
  7. Attempt to ping your desktop by name.  If you have a WINS server then make sure you have the IP address of the WINS server is set. If you are using your desktop to synchronize, then enter the IP address of the desktop as the WINS server on your Handheld PC or Pocket PC.   If the IP address that is resolved when you ping by name is not the same as your desktop, your PC's name is not unique or it is an invalid name.  You need to rename the other PC to resolve this issue if there is a duplicate name.  Another possible issue is that the PC's name can not have any spaces in it nor can the name contain underscores.  If this occurs, rename the PC, delete the partnership and then re-sync with the cradle.  Note: The Pocket PC 2002 remembers the IP address of the desktop so you should not need to enter it as the WINS server to synchronize.  You can use Pocket Hosts to configure a host file on your Pocket PC to work around this issue.  Pocket Hosts allows you to create a host entry on your Pocket PC so it will know what the IP address of your desktop is and just use the IP address only.  The same registry entry also works on the Handheld PC as well.
  8. If you are using the Pocket PC 2002 or Windows Mobile 2003  you must set your default connection in Connection Manager to Work in order to synchronize over a network. You will not be able to synchronize if you have your default setting to The Internet.   The Connection Manager is available at Start - Settings - Connections - Connections (and Advanced on Windows Mobile 2003).
  9. If you have more than one partnership and you wish to sync via ethernet or Wi-Fi you need to make sure you have selected the correct PC to sync with. This is done on the Pocket PC by launching ActiveSync and clicking on Tools - Options and selecting the PC you wish to sync with.
  10. You can check to see that Netbios is installed and working correctly by using NBTSTAT -n from a command line in Windows 95 or Windows NT.  This will list all known  Netbios hosts.  Check to see if your Handheld PC or Pocket PC's name is listed.  If it returns an error code of failed to "access NBTdriver 1" then you need to unbind and rebind Netbios to the TCP/IP stack.  This is done in the Start - Settings - Control Panel - Network.  If you can not see your Handheld PCs or Pocket PC's name then check that the Handheld PC or Pocket PC has the correct WINS server address configured.
  11. Now you should be able to sync.
  12. If you want to use the internet and sync, you need to manually enter the correct DNS entries as well.  The DNS entries are not acquired via DHCP if you entered  the WINS server.
  13. Check to see if you are using a Proxy Server. Note the IP address and port for the Proxy server and enter this information into Pocket Internet Explorer.  Note:  A socks or Winsock proxy is not supported on the Handheld PC or Pocket PC 2000.   Only an HTTP proxy is supported.  However with the Pocket PC 2002, Socks, Winsock and HTTP proxies are supported.  You must use the Work option in Connection Manager to use a proxy.

Now you are all set to use your Handheld PC or Pocket PC to access your network.

Related Articles

Connection Manager
Troubleshooting Dialup Connections
Network Utilities