How to Recompose Received MailMessage with Attachments

The program represents a Delphi tutorial that utilizes the Clever Mail Message and S/MIME Message components to parse / compose E-mail messages in MIME format, with file or image attachments.
When using the TclMailMessage component together with the POP3 or IMAP4 clients, the message parts are extracted and saved to the MailMessage members. If you save the message source with the TclMailMessage.SaveMessage method or access the message source via the TclMailMessage.MessageSource property, the message is recomposed. Since the attachmets are not stored in memory, the component raises the OnLoadAttachment event in order to get a stream with the attachment content. As a result, you will not get the original message content. If you want to get the origital source of the received message, please use the TclPop3.Response (TclImap4.Response) property instead. Otherwise, you will have to implement both the TclMailMessage.OnSaveAttachment and TclMailMessage.OnLoadAttachment event handers. This is necessary to save emails with attachments, and the given program shows you how to do this.
The other component, TclSMimeMessage, represents the TclMailMessage descendant and provides an additional functionality to encrypt/decrypt and sign/verify the message using the S/MIME standard.
The given program utilizes both these components and additionally allows saving digitally verified message source. Comments within the source code will help you to understand how the code works.
Using this tutorial as a starting point, you can implement your own storage for the attached files and images, including database tables and in-memory streams.
See also:
How to compile:
  1. Please clone the GitHub/CleverComponents/Clever-Internet-Suite-Tutorials repository.
  2. Download and install the Clever Internet Suite library.
  3. Open and compile the RecomposeMailMessage.dproj project in your Delphi IDE.
  4. Enjoy.
Please feel free to Contact Us and ask any program related questions.
Keep updated on Facebook   YouTube   Twitter   Telegram   Newsletter
Kind regards
Clever Components team

Add Feedback