Email Notifier with Microsoft Agent--- GENIE


Description 

Email notifier is TCP/IP application that notifies the user if there is email in the user's email server. This application checks email in default time interval of 5 minutes. You can change it with configure menu. this application is a Iconfied application. What I mean is that when you run it, it will appear in the right bottom corner as a icon. When you mouse right-click on it, you will see



If you choose Configure menu, you can configure settings, and you will see 



then you can configure

-POP3 Server

-POP3 Server Port

-User Name and Password

--Time Internal that the application checks email

I suggest you that you should enter these information, before you choose the menu "Check Email"

I improved this application by using Microsoft Agent character Genie. Genie will tell you how many emails you have. First of all you have to download Microsoft Agent SDK from the following URL and install it.

http://www.microsoft.com/msagent/downloads.htm



Genie will pop up and tells you the number of email

the following code makes Microsoft Agents work

public frmAgent(int EmailNumber)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
///you can download Agents from
///http://www.microsoft.com/msagent/downloads.htm
/// first load the character
Agent1.Characters.Load("Genie","Genie.acs");
AgentObjects.IAgentCtlCharacterEx genie=Agent1.Characters["Genie"];
AgentObjects.IAgentCtlRequest reg;
genie.Show(
false);
genie.Speak("You Have "+ EmailNumber.ToString()+" emails","");
genie.Think("Should I Leave or Stay, Himmm!!!!");
genie.Hide(
true);
}

Source Code:

private void EmailCheck()
{
TcpClient tcpClient =
new TcpClient();
try
{
tcpClient.Connect(txtPopServer.Text,Int32.Parse(txtPopPort.Text));
}
catch
{
MessageBox.Show("Cannot connect to target host "+txtPopServer.Text +" and port "+txtPopPort.Text);
}
///get the response of pop3 mail server
netStream = tcpClient.GetStream();
if(netStream == null)
{
throw new Exception("GetStream is null");
}
string returnMsg=ReadFromNetStream(ref netStream);
checkForError(returnMsg);
///send username information
WriteToNetStream(ref netStream, "USER " + this.txtUserName.Text);
returnMsg=ReadFromNetStream(
ref netStream);
checkForError(returnMsg);
///send password information
WriteToNetStream(ref netStream, "PASS " + this.txtPassword.Text);
returnMsg=ReadFromNetStream(
ref netStream);
checkForError(returnMsg);
Stat();
netStream.Close();
tcpClient.Close();
}
public void Stat()
{
WriteToNetStream(
ref netStream, "STAT");
string returnMsg=ReadFromNetStream(ref netStream);
checkForError(returnMsg);
///split the information of total message and total size
string[] TotalStat= returnMsg.Split(new char[] {' '});
int count=Int32.Parse(TotalStat[1]);
int totalSize=Int32.Parse(TotalStat[2]);
///the following code will call the Microsoft Agent (Genie Chracter)
frmAgent agent= new frmAgent(count); 
emailnot.Show();
}
private void WriteToNetStream(ref NetworkStream NetStream, string Command)
{
string stringToSend = Command + "\r\n";
Byte[] arrayToSend = Encoding.ASCII.GetBytes(stringToSend.ToCharArray());
NetStream.Write(arrayToSend, 0, arrayToSend.Length);
}
/// <summary>
///
this function reads from Network Stream
/// </summary>
///
<param name="NetStream"></param>
///
<returns></returns>
private String ReadFromNetStream(ref NetworkStream NetStream)
{
StringBuilder strReceived=
new StringBuilder();
StreamReader sr=
new StreamReader(NetStream);
String strLine = sr.ReadLine();
while(strLine==null || strLine.Length==0)
{
strLine = sr.ReadLine();
}
strReceived.Append(strLine);
if(sr.Peek()!=-1)
{
while ((strLine=sr.ReadLine())!=null)
{
strReceived.Append(strLine);
}
}
return strReceived.ToString();
}
/// <summary>
///
this function checks the error in the stream;
/// </summary>
///
<param name="s"></param>
private void checkForError(String strMessage)
{
if (strMessage.IndexOf("+OK") == -1)
throw new Exception("ERROR - . Recieved: " + strMessage);
}

Up Next
    Ebook Download
    View all
    Learn
    View all