Sample code for 30+ languages & platforms
Go

Render an Email to MIME in a StringBuilder

See more SMTP Examples

Demonstrates the Chilkat MailMan.RenderToMimeSb method, which renders an Email object as MIME text and appends the result to a StringBuilder, without sending the email. This example renders a message into a StringBuilder and prints it.

Background: This is the StringBuilder version of RenderToMime. Appending into a StringBuilder is more efficient when the MIME is large or when you plan to further inspect or manipulate it — searching, replacing, or accumulating additional text — without creating extra intermediate string copies.

Chilkat Go Downloads

Go
    success := false

    //  Demonstrates the MailMan.RenderToMimeSb method, which renders an Email object as MIME text
    //  and appends the result to a StringBuilder (without 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 in a StringBuilder.")

    //  Render the MIME into a StringBuilder.
    sbMime := chilkat.NewStringBuilder()

    success = mailman.RenderToMimeSb(email,sbMime)
    if success == false {
        fmt.Println(mailman.LastErrorText())
        mailman.DisposeMailMan()
        email.DisposeEmail()
        sbMime.DisposeStringBuilder()
        return
    }

    fmt.Println(*sbMime.GetAsString())

    mailman.DisposeMailMan()
    email.DisposeEmail()
    sbMime.DisposeStringBuilder()