Mega Code Archive

 
Categories / Delphi / Examples
 

Mailling list

Title: Mailling list Question: Sending mail to all recipients that you have added to your database Answer: First of all I am not so good in English so if you find some mistakes please try to undarstand me. After you have finished making your database (connection, dataset, etc.), do next: 1) Put text "comobj" (without quotes) into usees list 2) Put Edit, Memo 3) procedure TForm10.Action1Execute(Sender: TObject); //this procedure is attach to Action1, but you can attach following cod for anything you want (Button, Events) const olMailItem = 0; olByValue = 1; var OutlookApp, MailItem: OLEVariant; var i:integer; //this is for counter that will count record from your base begin edit1.Clear; // this is for clean up edit1 i:=0; Datasource1.DataSet.First; //this moves pointer to first record in database try OutlookApp := GetActiveOleObject('Outlook.Application'); except OutlookApp := CreateOleObject('Outlook.Application'); end; try MailItem := OutlookApp.CreateItem(olMailItem); repeat edit1.Text:=adoquery1Email.DisplayText; //this use edit1 to display text from your field Email, I have use Adoquery, because SQL, but if you have used AdoTable (for example ADOTable1)and want to display text from field (for example) TEST then it will be AdoTable1TEST.DisplayText MailItem.Recipients.Add(edit1.Text); //this is use to add email address to mailitem recipients from edit1 datasource1.DataSet.Next; //this move pointer to next record in your database i:=i+1; until i=adoquery1.RecordCount; //and email adress will be added until last record in database MailItem.Subject := 'Enter subject for your mail'; MailItem.Body :=Memo1.Text; // this is for message MailItem.Send; Showmessage('Mail send !!!'); // this is for showing message that your mail is send finally OutlookApp := VarNull; // to close outlook aplication end; end; Warning : After you enter this code try to run it, in case that your Outlook Express is not open you will get error message. But do not worry, message will be sent, if you do not belive me try to Compile code, after that run it (offcource run Nameofyourproject.exe, and enter your mail adress like recipients (offcource into field in your database where email address should be)and you will see that you get the Email message. P.S. Once again, sorry on bad english.