|
|
|
|
![]() ![]() |
Mar 13 2005, 02:39 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 318 Joined: 5-January 05 Member No.: 3,136 |
Here is a simple tutorial on how to make a useful little program that can check your e-mail inbox for new messages, and notify you about it. If you save the finished EXE file on your hard disk, you can also configure windows to start it automatically when windows is loaded, and get notified when your inbox is checked for new messages.
Here is a checklist on what you need: -Borland Delphi -Installed Indy components (these are automatically installed if you are using Delphi 6 or Delphi 7) Onward! Create a new project in Delphi. Select the Indy “IdPop3” component from the “Indy Clients” tab and place it on your form. ![]() Now, we need to make this component work. We will use this component to check our inbox when our program starts, and to do that, double click any part of the empty area on your form, and the code editor will show up allowing you to type the code that will be executed as soon as the form is created. ![]() First, we need to define the variable that is going to contain the number of new messages. In this case, I called it “Status”. When defining variables in Delphi, you need to put them behind the main “begin” statement of the procedure, like this: CODE procedure TForm1.FormCreate(Sender: TObject); var Status:Integer; begin end; This program will automatically end after we click on the OK button after we receive our notification, but the main form will still show up and hide itself very fast, which looks a bit ugly. So we will resize it and move it to the invisible part of the screen: CODE Form1.Width := 100; Form1.Height := 100; Form1.Left := -500; Form1.Top := -500; Good. Now we need to input the needed information about the pop3 server that we are connecting to. Don’t forget to type in your information here: CODE idPop31.Username := 'your_username'; idpop31.Password := 'your_password'; idpop31.Host := 'pop3.your_server.com'; Now for the code that will connect and retrieve the needed information. First we connect to the server, then the “idpop3” components retrieves the number of new messages, and disconnects from the server: CODE idpop31.Connect; Status:=idpop31.CheckMessages; idpop31.Disconnect; Let’s show our notification: If the number of messages is 0, the program will play a sound and show a message box that will inform us that we do not have any new messages. In this case, I used the “Windows XP Logoff” sound, but you can use any sound you like, as long as it is a WAV file: IMPORTANT: In order to play the sound, you need to place the “mmsystem” unit in the “Uses” form: ![]() CODE if Status = 0 then begin PlaySound('C:\WINDOWS\Media\Windows XP Logoff Sound.wav',0,SND_ASYNC); MessageDlg('You have no new messages.',mtInformation,[mbOK],0); end; If the message count is 1, then the program plays the “Windows XP Logon” sound and shows a notification message: CODE if Status = 1 then begin PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC); MessageDlg('You have 1 new message.',mtInformation,[mbOK],0); end; If the message count is larger than 1, then we do the same thing, except the message is slightly different: CODE if Status > 1 then begin PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC); MessageDlg('You have '+IntToStr(Status)+' new messages.',mtInformation,[mbOK],0); end; And finally, we close our program with this piece of code: CODE Application.Terminate; The whole unit should look like this: CODE unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, IdPOP3, mmsystem; type TForm1 = class(TForm) IdPOP31: TIdPOP3; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var Status:Integer; begin Form1.Width := 100; Form1.Height := 100; Form1.Left := -500; Form1.Top := -500; idPop31.Username := 'your_username'; idpop31.Password := 'your_password'; idpop31.Host := 'pop3.your_server.com'; idpop31.Connect; Status:=idpop31.CheckMessages; idpop31.Disconnect; if Status = 0 then begin PlaySound('C:\WINDOWS\Media\Windows XP Logoff Sound.wav',0,SND_ASYNC); MessageDlg('You have no new messages.',mtInformation,[mbOK],0); end; if Status = 1 then begin PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC); MessageDlg('You have 1 new message.',mtInformation,[mbOK],0); end; if Status > 1 then begin PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC); MessageDlg('You have '+IntToStr(Status)+' new messages.',mtInformation,[mbOK],0); end; Application.Terminate; end; end. Press F9 to run your program. If all goes as planned, the program will connect to your e-mail server and retrieve the number of new messages and display it as a dialog message: ![]() That’s about it! Any questions and comments are welcome. |
|
|
|
Mar 14 2005, 01:02 AM
Post
#2
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 661 Joined: 10-January 05 Member No.: 3,189 |
Nice tutorial, now i can stop using outlook, lol
|
|
|
|
Mar 16 2005, 10:41 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 318 Joined: 5-January 05 Member No.: 3,136 |
I guess you really can't get ANY MORE CREATIVE than that?
This is just the same scene when I wrote a tutorial about changing the start menu button caption. The start button was just AN EXAMPLE of what you could do with handles. This is also an example, and there are countless possibilities what you can do with it! In my case: 1)I extended this example and made a program that enables me be notified when I receive new e-mail messages when I turn on my computer, but I will also be notified when I receive an important message from my relatives. 2)I am also subscribed to a newsletter, and when I receive an email that is from the address that sends that newsletter, my program will automatically download it and show it on the screen (kind of like when somebody brings you the daily newspaper). 3)When I receive an e-mail from the phpBB newsletter, it usually means that a new security alert is found and/or there is a new version of phpBB available. There are many script kiddies around that get their hands on the fresh exploits around and can easily trash my forum. That's why I get notified right away when it arrives from my program. In a sea of unread e-mail messages, spam and other junk mail, this small program is very useful to me. BTW: When I read a tutorial, I usually try to learn something, not just follow the instructions, get the job done, congratulate myself on how smart and clever I am, and still know nothing. |
|
|
|
Mar 18 2005, 04:39 AM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 618 Joined: 30-October 04 From: Philippines Member No.: 2,049 |
Now, Delphi is a really user-friendly programming langauge! I must use it, i think. Or do you think I have to stick to VB? But I am not using VB for more than 2 years now. I love PHP though.
|
|
|
|
Mar 18 2005, 04:40 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 318 Joined: 5-January 05 Member No.: 3,136 |
If you know Visual Basic, you should have no problem when learning Object Pascal (Delphi, that is). Just remember to put ";" on the end of every line, and instead of the "{" bracket, you will be using the "begin" word, and instead of the "}" bracket, you will be using the "end;" word. Delphi is a very powerful programming language, but it still keeps its simplicity. It wouldn't hurt if you could take some time to learn it.
Check out these links if you are interested: www.borland.com - The makers of Delphi www.torry.net - A great web site where you can find allot of components, code examples and applications for Delphi www.delphi.about.com - There are some tutorials on this site, and lot's of nice articles (there is a bit more advertising than usual, but it pays off) |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 24th July 2008 - 05:15 AM |