home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 November / Chip_2002-11_cd1.bin / zkuste / delphi / kompon / d567 / MMAILER.ZIP / Unit1.pas < prev    next >
Pascal/Delphi Source File  |  2002-08-28  |  3KB  |  128 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, Menus, StdCtrls, mMailer, IdEMailAddress, Registry;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Edit1: TEdit;
  12.     mMailer1: TmMailer;
  13.     Edit2: TEdit;
  14.     Edit3: TEdit;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Label6: TLabel;
  18.     Label7: TLabel;
  19.     Memo1: TMemo;
  20.     MainMenu1: TMainMenu;
  21.     Setup1: TMenuItem;
  22.     Button1: TButton;
  23.     CheckBox1: TCheckBox;
  24.     ListBox1: TListBox;
  25.     Label3: TLabel;
  26.     Button2: TButton;
  27.     OpenDialog1: TOpenDialog;
  28.     procedure Setup1Click(Sender: TObject);
  29.     procedure Button1Click(Sender: TObject);
  30.     procedure Button2Click(Sender: TObject);
  31.   private
  32.     procedure CutOutStrs(Str, DelCh: string; var SStrs: TStringList);
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   Form1: TForm1;
  40.  
  41. implementation
  42.  
  43. uses Unit2;
  44.  
  45. {$R *.dfm}
  46.  
  47. procedure TForm1.Setup1Click(Sender: TObject);
  48. var
  49.   Reg: TRegistry;
  50. begin
  51.   Reg:= TRegistry.Create;
  52.   try
  53.     if SetupForm.ShowModal = mrOK then
  54.       with SetupForm do
  55.       begin
  56.         mMailer1.Host:= Edit1.Text;
  57.         mMailer1.UserId:= Edit2.Text;
  58.         mMailer1.Password:= Edit3.Text;
  59.         Reg.RootKey:= HKEY_CURRENT_USER;
  60.         if Reg.OpenKey('\software\mas prod.\TmMailer', true) then
  61.         begin
  62.           Reg.WriteString('Host', Edit1.Text);
  63.           Reg.WriteString('UserId', Edit2.Text);
  64.           Reg.WriteString('Password', Edit3.Text);
  65.         end;
  66.       end;
  67.   finally
  68.     Reg.Free;
  69.   end;
  70. end;
  71.  
  72. procedure TForm1.Button1Click(Sender: TObject);
  73. var
  74.   SStrs: TStringList;
  75.   n: Integer;
  76.   RItem: TIdEMailAddressItem;
  77. begin
  78.   SStrs:= TStringList.Create;
  79.   try
  80.     with mMailer1 do
  81.     begin
  82.       From.Address:= Edit1.Text;
  83.       // Get recipients
  84.       CutOutStrs(Edit2.Text, ';', SStrs);
  85.       for n:= 0 to SStrs.Count - 1 do
  86.       begin
  87.         RItem:= Recipients.Add;
  88.         RItem.Address:= Trim(SStrs[n]);
  89.       end;
  90.       Subject:= Edit3.Text;
  91.       Attachments.AttachedFiles.Text:= ListBox1.Items.Text;
  92.       Body.Text:= Memo1.Text;
  93.       HTML:= CheckBox1.Checked;
  94.       Send;
  95.     end;
  96.   finally
  97.     SStrs.Free;
  98.   end;
  99. end;
  100.  
  101. procedure TForm1.Button2Click(Sender: TObject);
  102. var
  103.   n: Integer;
  104. begin
  105.   if OpenDialog1.Execute then
  106.     for n:= 0 to OpenDialog1.Files.Count - 1 do
  107.       ListBox1.Items.Add(OpenDialog1.Files[n]);
  108. end;
  109.  
  110. procedure TForm1.CutOutStrs(Str, DelCh: string; var SStrs: TStringList);
  111. begin
  112.   SStrs.Clear;
  113.   if Pos(DelCh, Str) = 0 then
  114.   begin
  115.     SStrs.Add(Str);
  116.     Exit;
  117.   end;
  118.   while Pos(DelCh, Str) <> 0 do
  119.   begin
  120.     SStrs.Add(Copy(Str, 1, Pos(DelCh, Str) - 1));
  121.     Str:= Copy(Str, Pos(DelCh, Str) + 1, Length(Str));
  122.   end;
  123.   SStrs.Add(Str);
  124. end;
  125.  
  126. end.
  127.  
  128.