Link to home
Start Free TrialLog in
Avatar of videojack
videojack

asked on

Indy10 IdSMTP hickups

using D7se

i have 2 problems..
initially, my code will send an email..however, i never receive it..
i am using a ';' for delimiter for CC,..not sure if i should use  a , or a ;..
maybe thats problem1..

next big problem--
it sends once--A-OK..but thereafter, i get access violation error message..
i am not clearing something out..
any help--appreciated..thank you


procedure TfrmIndy.SendSMTPMail(V_Subject: String);
var
idAttach: TIdAttachmentFile;
htmpart, txtpart: TIdText;
V_Text: string;
V_To, V_CC: string;
V_html: string;
V_attac, V_file:string;
tempStr: string;
begin
   try
   if(frmLogs.shpShuttingDown.Brush.Color=clRed)then begin
      if(frmIndy.IdSMTP1.Connected)then frmIndy.IdSMTP1.Disconnect;
      sleep(100);
      frmLogs.shpSendSMTP.Brush.Color:=clSilver;
      application.ProcessMessages;
      end else begin
      frmMaster.pnlEmailStatus.color:=clSilver;
      application.ProcessMessages;
      //make sure we have an IP or dont try to send anything...
      if(frmSetup.lblIPaddress.Caption='')then begin
         if(frmLogs.shpGetIPaddress.Brush.Color<>clRed)then getIPaddress();
         sleep(10);
         while(frmLogs.shpGetIPaddress.Brush.Color=clRed)do begin
            application.ProcessMessages;
            end;
         end;
      if(frmSetup.lblIPaddress.Caption<>'')then begin
         try
         if(frmIndy.IdSMTP1.Connected)then frmIndy.IdSMTP1.Disconnect;
         sleep(200);
         except
         end;
 
      //not connected yet
      if(frmSetup.chkUseSSL.Checked)then begin
         frmIndy.idsmtp1.IOHandler:=frmIndy.IdSSLIOHandlerSocketOpenSSL1;
         frmIndy.IdSMTP1.UseTLS:=utUseRequireTLS;
         end else begin
         frmIndy.idsmtp1.IOHandler:=nil;
         frmIndy.IdSMTP1.UseTLS:=utNoTLSSupport;
         end;
   if(frmSetup.chkSendAuthentication.Checked)
      then frmIndy.IdSMTP1.AuthType:=satDefault
      else frmIndy.IdSMTP1.AuthType:=satNone;
 
   if(frmLogs.shpBtnSendTest.brush.Color=clLime)
      then frmSetup.mmoMailStatus.Lines.Add('IP is: '+frmSetup.lblIPaddress.Caption);
 
 
      //setup mail message
      //frmIndy.IdMessage1.MessageParts.Clear;
      frmIndy.IdMessage1:=TIdMessage.Create(nil);
      //frm who, to who, CC
      if(frmLogs.shpSendNWemail.Brush.Color<>clRed)
         then begin
         V_To:=frmSetup.mmoTo.Lines.Strings[0];
         frmSetup.mmoTo.Lines.Delimiter:=';';
         V_CC:=frmSetup.mmoTo.Lines.DelimitedText;
         end else begin
         V_To:=frmSetup.mmoNWto.Lines.Strings[0];
         frmSetup.mmoNWto.Lines.Delimiter:=';';
         V_CC:=frmSetup.mmoNWto.Lines.DelimitedText;
         end;
 
      //attachment
      V_html:='';
      V_attac:=frmSetup.edtAttachment.Text;
      V_file:=extractFileName(frmSetup.edtAttachment.Text);
 
      //body message
      frmSetup.Body.Lines.clear;
      application.ProcessMessages;
 
      if(frmLogs.shpSendNWemail.Brush.Color<>clRed)then begin
         if(frmMaster.btnStartMaster.Enabled=false)and
           (frmMaster.btnStopMaster.Enabled=true)
           then tempStr:='LOGGING'
           else tempStr:='NOT LOGGING';
         frmSetup.Body.Lines.Add('Watchman911Pro is: '+tempStr);
         end;
 
      if(frmSetup.chkAllowNeighborhoodWatchWebServer.Checked=false)
         then tempStr:=quotedStr('DISABLED')
         else tempStr:='';
      frmSetup.Body.Lines.Add(tempStr+' NeighborhoodWatch Pictures: http://'+
                                 frmSetup.lblIPaddress.caption+
                                 ':'+frmSetup.edtRemotePort.text
                                 +'/NWlogin.html');
 
      if(frmLogs.shpSendNWemail.Brush.Color<>clRed)then begin
         frmSetup.Body.Lines.Add('');
         if(frmSetup.chkAllowMyPrivateWebServer.Checked=false)
            then tempStr:=quotedStr('DISABLED')
            else tempStr:='';
         frmSetup.Body.Lines.Add(tempStr+' Private WebServer Pictures Database: http://'+
                                    frmSetup.lblIPaddress.caption+
                                    ':'+frmSetup.edtRemotePort.text
                                    +'/PRlogin.html');
 
         frmSetup.Body.Lines.Add('');
         frmSetup.Body.Lines.Add('FTP server(Databases Archive): ftp://'+
                                    frmSetup.lblIPaddress.caption+
                                    ':'+frmSetup.edtRemotePort.Text);
         end;
 
      application.ProcessMessages;
      V_Text:=frmSetup.Body.Text;
 
      //SetUp messaging
      frmIndy.IdMessage1.IsEncoded:=True;
      //SetUp from variables
      frmIndy.IdMessage1.CharSet:='iso-8859-1';
      frmIndy.IdMessage1.Encoding:=meMIME;
      frmIndy.IdMessage1.Subject:=V_Subject;
 
      frmIndy.IdMessage1.From.Text:=frmSetup.edtFrom.Text;  //'MyName@MyHost.it' ;
      frmIndy.IdMessage1.From.Name:='Watchman911Pro'; frmSetup.edtUserName.Text; //'NameDescriptionMail';
 
      frmIndy.IdMessage1.Recipients.Clear;
      frmIndy.IdMessage1.Recipients.add.Text:=V_To;
      frmIndy.IdMessage1.CCList.Clear;
      frmIndy.IdMessage1.CCList.Add.Text:=V_CC;
      frmIndy.IdMessage1.ContentType:='multipart/related';
      frmIndy.IdMessage1.Body.Clear;
 
      txtpart := TIdText.Create(frmIndy.IdMessage1.MessageParts);
      txtpart.Body.Text :=V_Text;
      txtpart.ContentType := 'text/plain';
      txtpart.ContentTransfer := '7bit';
 
      htmpart := TIdText.Create(frmIndy.IdMessage1.MessageParts);
      htmpart.Body.Text :=V_Html;
      htmpart.ContentType := 'text/html';
 
      if(trim(V_attac)='')then begin
         frmLogs.mmoErrorLog.lines.add('SendSMTPMail: trim(V_attac)=nil, aborting send');
         application.ProcessMessages;
         //result:=false;
         end;
 
      idAttach:=TIdAttachmentFile.Create(frmIndy.IdMessage1.MessageParts,V_attac);
      idAttach.ContentType := 'image/jpeg';
      idAttach.ExtraHeaders.Add('Content-ID: <'+V_file+'>');
      idAttach.ExtraHeaders.Values['content-id'] := V_file ;
      idAttach.DisplayName:= V_file ;
      idAttach.ContentDisposition := 'inline';
 
      frmIndy.idSMTP1.Host:=frmSetup.edtPostOffice.Text; //'smtp.MyHost.it' ;
      frmIndy.idSMTP1.Username:=frmSetup.edtUserName.Text; //'MyUser' ;
      frmIndy.idSMTP1.Password:=frmSetup.edtPassword.Text;       //'MyPW' ;
      frmIndy.IdSMTP1.Port:=strToInt(frmSetup.edtSMTPport.Text);
      frmIndy.IdSMTP1.ConnectTimeout:=10000;
      frmIndy.idsmtp1.ReadTimeout:=10000;
 
      frmMaster.lblEmailStatus.caption:='Connecting';
      if(frmLogs.shpBtnSendTest.brush.Color=clLime)
         then frmSetup.mmoMailStatus.lines.add('Connecting...');
      application.ProcessMessages;
 
      frmIndy.idSMTP1.Connect;
      application.ProcessMessages;
 
      if(frmLogs.shpBtnSendTest.brush.Color=clLime)
         then frmSetup.mmoMailStatus.Lines.Add('Sending...');
      application.ProcessMessages;
      frmIndy.idSMTP1.Send(frmIndy.IdMessage1);
 
      if(frmLogs.shpBtnSendTest.brush.Color=clLime)
         then frmSetup.mmoMailStatus.Lines.Add('DisConnecting...');
      frmIndy.idSMTP1.Disconnect;
      application.ProcessMessages;
 
      frmIndy.IdMessage1.Free;
      frmIndy.idSMTP1.Free;
      //frmIndy.IdMessage1.MessageParts.CleanupInstance;
      frmMaster.lblEmailStatus.caption:='Sent';
      frmMaster.pnlEmailStatus.color:=clGreen;
      application.ProcessMessages;
      if(frmLogs.shpBtnSendTest.brush.Color=clLime)
         then frmSetup.mmoMailStatus.Lines.Add('Sent');
      application.ProcessMessages;
      end;
   end;
 
   except on E:Exception do begin
      frmMaster.lblEmailStatus.caption:='Send Error';
      if(frmLogs.shpBtnSendTest.brush.Color=clLime)then begin
         frmSetup.mmoMailStatus.lines.add('Send Error');
         frmSetup.mmoMailStatus.Lines.Add('ERROR: ' +E.ClassName+' '+E.Message);
         end;
      frmMaster.pnlEmailStatus.color:=clRed;
      application.ProcessMessages;
 
      frmLogs.mmoErrorLog.Lines.Add(dateTimeToStr(now)+' SendSMTPMail: '+E.ClassName+' '+E.Message);
 
      try
      if(frmIndy.IdSMTP1.Connected)then frmIndy.IdSMTP1.Disconnect;
      sleep(100);
      frmIndy.IdMessage1.Free;
      frmIndy.idSMTP1.Free;
      except
      end;
 
      end;
   end;
 
   frmLogs.shpSendSMTP.brush.Color:=clSilver;
   application.ProcessMessages;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of videojack
videojack

ASKER

thankyou..
that took me in the right direction..i now longer have the second email--
failure..and it mails correctly..

i still have a problem with ssl.. it errors--cant read ssl or something..
i will post a 500 question on it..thanks again/..jack