Rank: Newbie
Groups: Registered
Joined: 2/15/2017(UTC)
Posts: 2
Hello, in Delphi, I want to send a file as attachment which is stored in a TFileStream. Does anyone know how to do this and could post the code for it? I could only find examples for sending a file which is on my harddisk or a http source. Thanks, Chris
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Hi, you can use AddAttachment1 method:
https://www.emailarchite...l/sdk/?ct=addattachment1 Here is the example codes to convert MemoryStream to VARIANT, you need to read file to memory stream, then use AddAttachment1
Code: function MemoryStreamToOleVariant(Strm: TMemoryStream): OleVariant;
var
Data: PByteArray;
begin
Result := VarArrayCreate([0, Strm.Size - 1], varByte);
Data := VarArrayLock(Result);
try
Strm.Position := 0;
Strm.ReadBuffer(Data^, Strm.Size);
finally
VarArrayUnlock(Result);
end;
end;
Additional example codes (OleVariant to TMemoryStream)
Code:
function OleVariantToMemoryStream(data: OleVariant): TMemoryStream;
var
ms: TMemoryStream;
i, len, lbound, ubound: integer;
buffer: array of byte;
begin
result := TMemoryStream.Create;
lbound := VarArrayLowBound(data, 1);
ubound := VarArrayHighBound(data, 1);
len := ubound - lbound + 1;
if len = 0 then
exit;
SetLength(buffer, len);
for i := lbound to ubound do
begin
buffer[i] := VarArrayGet(data, i);
end;
result.WriteBuffer(buffer[0], len);
result.Seek(0, soFromBeginning);
end;
Edited by user Friday, December 11, 2020 5:11:06 PM(UTC)
| Reason: Not specified
Rank: Newbie
Groups: Registered
Joined: 2/15/2017(UTC)
Posts: 2
Thank you very much!! This works for me :-)
Forum Jump
EmailArchitect Support
Email Component Development
- EASendMail SMTP Component - .NET Version
- EASendMail SMTP Component - Windows Store Apps
- EASendMail SMTP ActiveX Object
- EAGetMail POP3 & IMAP4 Component - .NET Version
- EAGetMail POP3 & IMAP4 ActiveX Object
Exchange Server and IIS SMTP Plugin
- DomanKeys/DKIM for Exchange Server and IIS SMTP
- Disclaimer and S/MIME for Exchange Server and IIS
EmailArchitect Email Server
- EmailArchitect Email Server (General)
- EmailArchitect Email Server Development
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.