EldoS | Feel safer!

Software components for data protection, secure storage and transfer

S/MIME mesaging

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
Posted: 01/09/2008 08:30:13
by Stephane Grobety (Priority Standard support level)
Joined: 04/18/2006
Posts: 172


I'm struggling to write a simple S/MIME communication facility (Delphi 6). I have tried to make sense of the "SecureMail" demo but, unfortunately, I cannot praise the clarity or even relevance of that sample with real world implementation (not even counting the fact that it doesn't compile at all unless you fix several problems).

What I have tried:

Create a new TElSimpleSMIMEMessage instance, populate the fields mail fields (from, to, Subject, BodyPlain, etc.), use the AddAttachment method to add my data file, assign a memory store containing the encryption X509 cert to the EncryptCertStorage property and set the SMIMEOptions to encrypt without signing. The result is a message without any MIME section definition and and made only of a base64 body which is too short to contain my data file or even the content of the BodyPlain property.

Create a new TElMessage instance and try to build it from scratch. Unfortunately, I couldn't find any way to do that that wouldn't result in an AV when trying to access the message parts.

So, what I am asking for is:

- Is there a sample, somewhere on how to use the TElSimpleSMIMEMessage class ?
- Same question about TElMessage but, more specifically, something that demonstrate (if possible, in a way that isn't designed to minimize the number of lines in the sample but rather to help understand how the class is supposed to be used).

Alternatively, if someone has a sample that make use of ANY of the SMIME classes for encryption and decryption, that would do the trick if the sample looks like a "normal" mail app, not a wizard that requires pre-crafted data to do anything.

Posted: 01/09/2008 10:02:06
by Eugene Mayevski (EldoS Corp.)

There are no samples for ElSimpleSMIMEMessage but it works correctly (we have a couple of test cases to run).
I can't answer any of your other questions as they contain no useful information about the actual problem.

Sincerely yours
Eugene Mayevski
Posted: 01/09/2008 10:53:45
by Eugene Mayevski (EldoS Corp.)

Here's the code that works:

procedure TForm1.Button1Click(Sender: TObject);
var Message : TElSimpleSMIMEMessage;
    CertStorage : TElMemoryCertStorage;
    Stream : TFileStream;
  CertStorage := TElMemoryCertStorage.Create(nil);
  Stream := TFileStream.Create('c:\projects\secureblackbox\certificates\cert.pfx', fmOpenRead);
    CertStorage.LoadFromStreamPFX(Stream, 'password');

  Client := TElSmtpClient.Create(nil);
  Client.Address := 'XXX';
  Client.Port := 25;
  Client.Username := 'YYY';
  Client.Password := 'ZZZ';
  Client.AllowBinaryMode := true;
  Client.UseSSL := false;
  Client.OnProgress := HandleProgress;
  Client.OnCertificateValidate := HandleCertificateValidate;

  Message := TElSimpleSMIMEMessage.Create(nil);
  Message.From := 'mayevski@eldos.com';
  Message.Subject := 'Attachment test 4';
  Message.BodyPlain.Text := 'Test of attachments';

  Message.SMIMEOptions.EncryptMessage := true;
  Message.EncryptCertStorage := CertStorage;

  Message.Attachments[0].Name := 'RawDisk.ico';
  Message.Attachments[0].ContentType := 'image/jpeg';
  Message.Attachments[0].ContentStream := TMemoryStream.Create;
  Stream := TFileStream.Create('C:\Temp\RawDisk.ico', fmOpenRead or fmShareDenyWrite);
  Message.Attachments[0].ContentStream.CopyFrom(Stream, Stream.Size);
  Message.Attachments[0].ContentStream.Position := 0;
  Message.Attachments[0].ContentId := 'anything';


Sincerely yours
Eugene Mayevski



Topic viewed 1705 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!