🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.delphi.general
2 messages
2 total messages Started by Wesley Wed, 15 Jul 2009 07:48
Sending an attachment as stream (with Indy in Delphi 2007)
#138
Author: Wesley
Date: Wed, 15 Jul 2009 07:48
72 lines
3316 bytes
Hello,

Can somebody help me?

I want to send an email with a picture as an attachment via Delphi
2007/Indy. But I don't know how?
Important is too. The picture has added as a stream in the email.
(without a temporary jpg-file).

Thank you, Wesley

This is mine example code:

uses
  SysUtils, Classes, EncdDecd,
  IdMessage, IdSMTP, IdGlobal, IdSMTPBase, IdAttachment,
IdMessageParts;

procedure InitSmtp(var ASmtp: TIdSMTP);
begin
  ASmtp.AuthType := atNone;
  ASmtp.CreateIOHandler;
  ASmtp.IOHandler.MaxLineAction := maSplit;
  ASmtp.Port := 25;
  ASmtp.ReadTimeout := 0;
  ASmtp.Host := FEmailServer;
end;

procedure BuildMessage(var AMessage: TIdMessage);
begin
  AMessage.Encoding := meMIME;
  AMessage.From.Text := 'MyName';
  AMessage.Recipients.EMailAddresses := FEmailAddress;
  AMessage.Subject := 'This is a test';
  AMessage.Body.Clear;
  AMessage.Body.Add('Screenshot at ' + DateTimeToStr(Now));
end;

procedure SendMessage(ASmtp: TIdSMTP; AMessage: TIdMessage);
begin
  ASmtp.Connect;
  try
    ASmtp.Send(AMessage);
  except
    on E: Exception do
      ShowMessageMessage('Can''t Send A Message');
  end;
  ASmtp.Disconnect;
end;

procedure CreateEmail;
var
  _StringStream: TStringStream;
  _Smtp: TIdSMTP;
  _Message: TIdMessage;
  _Attachment: TIdAttachment;
begin
  _StringStream := TStringStream.Create(DecodeString(FDataString)); //
<= base64-format (A Picture-save as string)
  _Smtp := TIdSMTP.Create(nil);
  _Message := TIdMessage.Create(nil);
  InitSmtp(lSmtp);
  BuildMessage(lMessage);

  _Attachment := TIdAttachment.Create(_Message.MessageParts, 'A
ScreenShot'); // <= getting an error message: Too many parameters);
  _Attachment.SaveToStream(_StringStream);

  SendMessage(_Smtp, _Message);
  _Message.Free;
  _Smtp.Free;
end;
Problem with deletion from DB
#139
Author: Pradeep VN
Date: Thu, 03 Sep 2009 06:13
51 lines
2669 bytes
Hi all,
   Can anyone please help me in the following?
   I am working on a db application. I have two procedures that
deletes data from two different tables, each of which look like the
following:

procedure TDBSaver.DeleteTableA(
  aID: integer);
begin
  with TDOAQuery.Create(nil) do
  try
    sql.add('DELETE FROM TABLEA WHERE ID = :ID');
    DeclareAndSet('ID', otInteger, aID);
    Execute;
    try
      Session.Commit;
    except on E:EOracleError do
      begin
        ShowMessage(E.Message);
        Session.RollBack;
      end;
    end;
  finally
    free;
  end;
end;
Similarly I have a DeleteTableB procedure too. But now I want to call
these two procedures as a single transaction. ie, The procedure
should
commit only if the data are deleted from both of the tables. Something
like:

DeleteTableA;
DeleteTableB;
try
  session.commit;
 except on E:EOracleError do
  session.RollBack;
end;


 But, since each of these procedures has a call to "COMMIT", the data
are deleted even if  there is an error in the following function call.
Since sometimes I want to delete data separately from TABLEA or
TABLEB , I don't want to embed the two delete calls into a single
procedure. Please suggest me a way to override the commit statement
inside the procedures so that I can achieve the deletions as a single
transaction

Thank you all in advance,
Pradeep
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads