Adding text and attachments to the E-mail message

The easiest way to compose a new mail message is to use the BuildMessage method of the TclMailmessage component. Please check the following document for more details: Build E-mail Message
This method automatically creates the appropriate body structure. If you decide to add attachments manually, you will have to compose this body structure by yourself.
E.g., if the message has a text body, and two attachments, the code will look like the following:
 
clMailMessage1.Clear();
clMailMessage1.Bodies.AddText('text lines');
clMailMessage1.Bodies.AddAttachment('filename1.ext');
clMailMessage1.Bodies.AddAttachment('filename2.ext');
clMailMessage1.ContentType := 'multipart/mixed';
 
But, if your message includes both the text and the HTML content, you will have to add an intermediate MultipartBody and assign the bodies properties according to RFC 2822 standard.
 
clMailMessage1.Clear();

multipartBody := clMailMessage1.Bodies.AddMultipart();
multipartBody.Bodies.AddText('text lines');
multipartBody.Bodies.AddHtml('<html>...');
multipartBody.ContentType := 'multipart/alternative';

clMailMessage1.Bodies.AddAttachment('filename1.ext');
clMailMessage1.Bodies.AddAttachment('filename2.ext');
clMailMessage1.ContentType := 'multipart/mixed';
The BuildMessage method performs this task for you.

Add Feedback