Sending Mail with Attachments from Memory Stream

Applies to Clever Internet Suite starting from version 7.1 and higher.
 
1. Composing a new message.
procedure TForm1.btnSendClick(Sender: TObject);
begin
  //composing a new message
  clMailMessage1.BuildMessage('The message text', ['filename.ext']);
  clMailMessage1.Subject := 'Subject line follows here';
  clMailMessage1.From.FullAddress := 'sender@domain.com';
  clMailMessage1.ToList.Clear();
  clMailMessage1.ToList.Add('recipient@another.com');

  //sending the message
end;
2. The event handler for the TclMailMessage.OnLoadAttachment event.
procedure TForm1.clMailMessage1LoadAttachment(Sender: TObject;
  ABody: TclAttachmentBody; var AFileName: string; var AData: TStream;
  var Handled: Boolean);
begin
  if (AFileName = 'filename.ext') then
  begin
    //loading the attachment content from a database
    AData := TMemoryStream.Create();
    BlobField1.SaveToStream(AData);
    AData.Position := 0;
    Handled := True;
  end;
end;

Add Feedback