If you have ever wanted to send email messages from your Delphi application, this article is for you. Jacques Noah explains how to use the open source Indy suite to set up an full fledged Mail Client.
Creating an Email Client with Borland Delphi - What you need (Page 2 of 4 )
You need to have Indy 9 or 10 installed. If you have Delphi 6 and above, then you can skip this section; otherwise go to www.indyproject.org and download the version appropriate to your Delphi version. I am using Delphi 7 and Indy 10.0.52. There are proper guides on how to install Indy on your computer.
I'm writing this tutorial on the assumption that you know how to use Delphi. If this is not the case then I would recommend you go to http://delphi.about.com for a beginner's course, before continuing.
Lets' get started!
Start up Delphi and create a new application - File | new | Application. For the purposes of this tutorial I will save the unit as mailer and the project as emailer. You can save it as anything you like. Drop a memo, five edit boxes, five static labels, a list box and two buttons on the form. Call button one "btBrowse" and button two "btMsg". Name the listview as lvAttachments and the five edit boxes as edTo, edFrom, edSubject, edCC, edBC. Call the five static labels From, To, CC, BC and subject. Also add a checkbox, an opendialog and another static label, and name it attachments. Go to the Indy Clients tab and get the idSMTP component, then go to the Indy Misc tab and get the idmessage component, and drop both of them onto the form.
Indy Clients tab:
Indy Misc tab:
Now let me explain what these two components are and what use they are to our application.
IdSMTP: This is basically a component that allows you to connect and communicate with the SMTP Server. To connect to an SMTP Server you need to have a hostname and password. These are usually available from your ISP, unless of course you installed your own SMTP server.
IdMessage: This is a component that will take in all the headers of a message, such as who the message is from, who it is going to, the subject, body, CC and BCC. In other words, all the headers that you see on email messages. In addition, this component also handles the attachment(s) that you will send with your messages.
To summarize:
IdSMTP allows you to connect to the (SMTP) server with the host and password parameters and is also the component that actually sends the message. Without this component the message won't go anywhere. IdMessage component holds all the message headers, including any attachments. IdMessage literally needs to be filled with the message parts.
At this point your application should look something like this: