Home arrow Delphi-Kylix arrow Page 5 - Building a Mailing List with Borland Delphi
DELPHI-KYLIX

Building a Mailing List with Borland Delphi


Mailing lists can be useful for a variety of purposes. If you have a newsletter that you use to communicate with your customers, chances are you use a mailing list. This article, the first of two parts, will show you how to build a mailing list application.

Author Info:
By: Leidago
Rating: 4 stars4 stars4 stars4 stars4 stars / 3
September 27, 2006
TABLE OF CONTENTS:
  1. · Building a Mailing List with Borland Delphi
  2. · The Database
  3. · Building the GUI for the Application
  4. · How the program works
  5. · Status reports

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building a Mailing List with Borland Delphi - Status reports
(Page 5 of 5 )

There are two types of status reports being displayed when the program is running. The one with the colorful text is created by the code. It actually just indicates what is happening in terms of how many messages are being sent or how many messages are left to be sent. The second type of status report is done automatically by the  idsmtp component. On the screen shot, take a look at the memo component just below the "send mail" button to see what I'm talking about. Let's add the code that makes this possible. Double click on the idsmtp's OnStatus event and add the following code:

procedure TForm1.IdSMTPStatus(ASender: TObject; const AStatus: TIdStatus;
  const AStatusText: String);
begin
memo2.Lines.Add(AStatustext);
end;

The Send to All option

This option requires nowhere near the amount of code that we needed for the other option. It is relatively straightforward. All we do here is retrieve ALL the email addresses in the database:

if rb2.Checked then begin
 query1.Close;
query1.sql.Text:='SELECT * FROM contacts ';
query1.Open;

Then we run a "while" loop to retrieve the email addresses one-by-one and then send the message off, while at the same time giving a visual report of what is happening:

while not query1.Eof do begin
re.Perform(EM_SETSEL, -1, -1);
re.SelAttributes.Color:= clGreen;
re.SelAttributes.Style:=[fsBold];
re.SelText:='Sending message#: ' +inttostr(query1.RecNo)+ ' of
' ;
re.Perform(EM_SETSEL, -1, -1);
re.SelAttributes.Color:= clBlack;
re.SelText:=inttostr(query1.RecordCount)+#13#10;
idmessage.Recipients.EMailAddresses:=
  query1.fieldbyname('email').Text;
try
idSMTP.send(idmessage);
except
on E: EIdSMTPReplyError do
    begin
    ShowMessage(E.Message);
Exit;
    end;
end;
query1.Next;
end;

When all the messages have been sent, a message is displayed and the connection is discontinued:

re.Perform(EM_SETSEL, -1, -1);
re.SelAttributes.Color:= clRed;
re.SelAttributes.Style:=[fsBold];
re.SelText:='All messages have been successfully sent.';
if idsmtp.Connected then idsmtp.Disconnect;
end;
Error reporting

In both options, I've put the sending of the email messages in a try...except block, so that if there is an error, it will be displayed in a dialog box and the sending of the email messages will be stopped:

try
idSMTP.send(idmessage);
except
on E: EIdSMTPReplyError do
    begin
    ShowMessage(E.Message);
Exit;
    end;

In the next part we will look at how to manage our contact details.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials