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;
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