EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Get TElMessage Header as String

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#25164
Posted: 06/03/2013 07:59:07
by Anne Onyme (Basic support level)
Joined: 02/20/2013
Posts: 7

Dear,

for my project, I need to get the entire Header of a TElMessage Object as a String. Is it possible ? I work with Delphi 7;

Sincerelly

Clement Cessin
#25167
Posted: 06/03/2013 08:16:06
by Alexander Ionov (EldoS Corp.)

Thank you for contacting us.

Please clarify do you compose a message using TElMessage class, or do you parse a message from a stream/file?
If you create a new message, do you need the entire header before the message is assembled an written to a stream?
If you parse a message from a stream, you can use GetHeaderFromStream function which can be found in the SBMIME unit.


--
Best regards,
Alexander Ionov
#25169
Posted: 06/03/2013 09:13:17
by Anne Onyme (Basic support level)
Joined: 02/20/2013
Posts: 7

Dear Alexander Ionov,

I compose a message using TELMessage class. I would like ta get the entire Header after sending the message (after the message is assembled) just for a history.

Sincerelly

Clement Cessin
#25170
Posted: 06/03/2013 09:46:58
by Alexander Ionov (EldoS Corp.)

If you compose a message to a stream before sending, you can use the mentioned function GetHeaderFromStream from the SBMIME unit. Just rewind the stream and use the function.
If you send a message using our SMTP component, then you can try to use TElMessage.MainPart.Header.Assemble method.
But it's better to use the first way. Using the first way, you'll be sure you have the same header as the one was sent. Using the second way, you will assemble the header again and result may be different from the data sent to the recipient.


--
Best regards,
Alexander Ionov
#25171
Posted: 06/03/2013 09:53:59
by Anne Onyme (Basic support level)
Joined: 02/20/2013
Posts: 7

Dear Alexander Ionov,

I use your SMTP component. I can't find any Assemble method in the TElMessageHeader class.

Actually, I search the way to have an assembled header with your components.

Sincerelly

Clement Cessin
#25172
Posted: 06/03/2013 10:11:42
by Alexander Ionov (EldoS Corp.)

As soon as you need to store the header for historical purposes only, I'd suggest to use the following way:
1. Assemble a newly created message using TElMessage.Assemble method to a temorary (memory of file depending on the message size) stream;
2. Use TElSMTPClient.Send(const MailFrom: string; RcptTo: TStringList; Message: TStream) method to send the assembled message;
3. Rewind the stream using Stream.Position := 0;
4. Use GetHeaderFromStream function to obtain the sent header.

Later we'll add a new Send method which will accept only a message stream, without two first parameters.


--
Best regards,
Alexander Ionov
#25181
Posted: 06/04/2013 02:11:46
by Anne Onyme (Basic support level)
Joined: 02/20/2013
Posts: 7

I've got an AccessViolation when I try to rewind the stream :

TElMessage.MainPart.Stream.Position := 0

Sincerelly

Clement Cessin
#25183
Posted: 06/04/2013 03:38:47
by Alexander Ionov (EldoS Corp.)

I meant something like the following:
Code
TempStream := TMemoryStream.Create();
try
  if MyMessage.Assemble(TempStream, ...) <> EL_OK then
    raise Exception.Create('Failed to assemble a message');

  TempStream.Position := 0;
  SmtpClient.Send(..., TempStream);

  TempStream.Position := 0;
  MyHeader := GetHeaderFromStream(TempStream); // <-- in MyHeader you have the required message header
finally
  FreeAndNil(TempStream);
end;


--
Best regards,
Alexander Ionov
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

Topic viewed 888 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!