Go
Go
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 Go Downloads
// 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.
mailman := chilkat.NewMailMan()
// Build the email to render.
email := chilkat.NewEmail()
email.SetSubject("Rendered email")
email.SetFrom("alice@example.com")
email.AddTo("Bob","bob@example.com")
email.SetBody("This message is rendered to MIME, not sent.")
// Render to MIME (no connection to the SMTP server is made).
mime := mailman.RenderToMime(email)
fmt.Println(*mime)
// 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.
mailman.DisposeMailMan()
email.DisposeEmail()