Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / C++/CLI

Desktop GMail Alert System

Rate me:
Please Sign up or sign in to vote.
3.27/5 (13 votes)
17 Jul 2006CPOL3 min read 54.6K   1.7K   23   3
Alert GMail user when the mails come

Sample image

Introduction

I created a sample project for checking the GMail account of a user and notify him / her using a task bar notifier and also using a Microsoft Agent. The users can also log via a web proxy as I did this work.

The ones who have not been set up a web proxy can happily remove the web proxy authentication part of the code.

I used ‘AxInterop.HTTSLib’ library for connecting to the GMail server and getting the HttpWebRequest & HttpWebResponse.

I also used ‘AxInterop.AgentObjects’ lib for calling the Microsoft Agent. You have to paste the ‘James.acs’ file in:

‘C:\WINDOWS\msagent\chars’

folder. You also need to keep it in the Resources folder. For the time being, I used the default character, that is merlin, in the source. Anyway, the use of James char is also in the source. Please refer to it for more information.

The proxy enabled version can also be used in a non proxy environment - type anything as the proxy username & password. Then try it.

Background + Prerequisites

You should have pre installed the .NET version 1.1 for testing of this code. It's freely available from the Microsoft site.

Download .NET 1.1 redistributable package from here.

And also the Microsoft Agent core components from Microsoft @ free to speak the character and show it you have to install those tools.

Please refer to this link and this one for details of the HTTP classes.

And use http://www.microsoft.com site for more information on Agent technology and Visual Studio .NET 2003.

Using the Code

Please create the HTML comment web pages using .NET IDE. Then you can view the entire solution comments via it or manually.

Please note that this is my first article, so there may be few reading problems.

But I used the Camel notation in my code as much as possible.

Also look at the task bar notification area icon. You can view the state by moving the cursor on to that icon, and by double clicking on that, you can exit from the application.

Please check the comments that I provided in the code.

C++
//create the web request to get the XML from the GMail server.
//WebRequest* myReq  = WebRequest::Create();
request = dynamic_cast<HTTPWEBREQUEST*>(WebRequest::Create(
          "https://mail.google.com/mail/feed/atom"));

WebProxy* myProxy = new WebProxy();
myProxy = dynamic_cast<WEBPROXY*>(request->Proxy);

//set proxy username & password (credential)
myProxy->Credentials = new NetworkCredential(sProxyUserName, sProxyPwd);
request->Proxy = myProxy;

 //set GMail username & password (credential)
request->Credentials = new NetworkCredential(sGMailUserName, sGMailPwd);

//get the response from the GMail server
resp = dynamic_cast<HTTPWEBRESPONSE*>(request->GetResponse());

if (request->HaveResponse)
{
    resp = dynamic_cast<HTTPWEBRESPONSE*>(request->GetResponse());
    str  = resp->GetResponseStream();

    while(true)
    {
        iReadBytes = str->Read(mybuf, 0, mybuf->Length);
        sReplyXMLSub = 
          System::Text::Encoding::UTF8->GetString(mybuf, 0, iReadBytes);

        if(iReadBytes == 0)
            break;
        sReplyXML = String::Concat(sReplyXML, sReplyXMLSub);
    }

    sReplyXML->Trim();

    xmlDoc->LoadXml(sReplyXML);

    //xmlDoc->Save("UserXML.xml");

    XmlNodeReader* reader = new XmlNodeReader(xmlDoc);

    while ( reader->Read() )
    {
        switch ( reader->NodeType )
        {
            case XmlNodeType::Element:

                if(String::Equals("fullcount", reader->Name))
                {
                    Unreaded = reader->ReadString();
                    sFullCount = String::Concat("You have ", 
                                 Unreaded, " Mails in your inbox");

                    agentObj->AgentCaller(sFullCount);
                    notifyIcon1->Text = sFullCount;

                    /*Enable the class for test the Text to Voice engine support.
                    but u may want a build environment to test this part.*/

                    //MailReader = new GMailReader(unlabel);
                    //MailReader->Show();
                }
        break;
        }
    }

The handling of the Microsoft Agent has been done using this block of code. But at first, you should paste the James.acs file in the ‘C:\WINDOWS\msagent\chars’ folder.

C++
String* sBaseDir = System::Environment::CurrentDirectory;
//place the character in the Resources folder
String* sCharPath = String::Concat(sBaseDir, "\\Resources\\James.acs");

//load the James character
this->axAgent1->Characters->Load("james", sCharPath);

Interop::AgentObjects::IAgentCtlCharacters* get_chars = 
                      this->axAgent1->get_Characters();
Interop::AgentObjects::IAgentCtlCharacter* schar = 
                    get_chars->Character("james");

//cast it to a IAgentCtlCharacter to get the maximum use
this->speaker     = schar;

I created a new thread to handle the Agent on the Application, and on the destructor of the AgentReader class, I destroy the speaker COM Object.

C++
agentObj = new AgentReader(speaker, sReplyXML);
//add the object to the thread.
Thread * AgentTrd = new Thread( new ThreadStart(agentObj, 
                                &AgentReader::MainAgentHandler));
AgentTrd->Start();

Points of Interest

I learned about how to cast variables or objects in Visual C++ .NET way in this project.

I also created Agent object in the VC++ code. To do it, I used this article from CodeProject.

I also tried some way of TTS engine support. I commented that part of the code for the time being. So you can try that too in your experiments and keep me posted about the results.

Thanks!

Additional Resources

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Mixed Reality Lab, National University of Singapor
Singapore Singapore
Graduate student of Mixed Reality Lab, National University of Singapore

Comments and Discussions

 
Generalhi Pin
sarithak5485-Apr-07 2:46
sarithak5485-Apr-07 2:46 
Generaldoubt Pin
Member 384883220-Feb-07 18:52
Member 384883220-Feb-07 18:52 
GeneralRe: doubt Pin
Nimesha Ranasinghe29-Oct-07 19:45
Nimesha Ranasinghe29-Oct-07 19:45 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.