Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 5 - Building a Mailing List with Borland Delph...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Building a Mailing List with Borland Delphi
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-09-27

    Table of Contents:
  • Building a Mailing List with Borland Delphi
  • The Database
  • Building the GUI for the Application
  • How the program works
  • Status reports

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

       · I have tested the sample code included, with Delphi 6 and 7 and it worked fine. If...
       · Hi, i tried the download file but i get the following error: [Fatal Error]...
     

    DELPHI-KYLIX ARTICLES

    - 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...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway