DataFlex
DataFlex
Render an Email to MIME Without Sending
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMime method, which renders an Email object as the MIME text that would be sent to the SMTP server, without actually sending it. This example builds a message and prints the rendered MIME.
Background: Rendering shows you exactly what
MailMan would put on the wire — including headers it adds at send time and any signing/encryption — which is invaluable for debugging or logging before committing to a send. Notably, the Date header is filled in with the current date/time and a unique Message-ID is generated, while headers such as Content-Type, Content-Transfer-Encoding, X-Priority, and MIME-Version match what Email.GetMime would produce. Nothing is transmitted, so no SMTP connection is made.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoMailman
Variant vEmail
Handle hoEmail
Boolean iSuccess
String sMime
// Demonstrates the MailMan.RenderToMime method, which renders an Email object as the MIME
// text that would be sent to the SMTP server, without actually sending the email.
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Build the email to render.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Rendered email"
Set ComFrom Of hoEmail To "alice@example.com"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Set ComBody Of hoEmail To "This message is rendered to MIME, not sent."
// Render to MIME (no connection to the SMTP server is made).
Get pvComObject of hoEmail to vEmail
Get ComRenderToMime Of hoMailman vEmail To sMime
Showln sMime
// Sample output:
//
// MIME-Version: 1.0
// Date: Fri, 17 Jul 2026 05:25:42 -0500
// Message-ID: <E13F164829E44779462366BF1D8020CA210F8F1F@CHILKAT25>
// Content-Type: text/plain; charset=us-ascii; format=flowed
// Content-Transfer-Encoding: 7bit
// X-Priority: 3 (Normal)
// Subject: Rendered email
// From: alice@example.com
// To: Bob <bob@example.com>
//
// This message is rendered to MIME, not sent.
//
// Note: The Date header is automatically added with the current date/time, and a unique
// Message-ID header is generated and added. The other headers (Content-Type,
// Content-Transfer-Encoding, X-Priority, and MIME-Version) have the same values you would
// see with Email.GetMime.
End_Procedure