Go Requires Chilkat v11.0.0+
Go
Create an HTML preview with embedded images
See more Email Object Examples
Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.
Chilkat Go Downloads
success := false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := chilkat.NewEmail()
success = email.LoadEml("with-attachments.eml")
if success != true {
fmt.Println(email.LastErrorText())
email.DisposeEmail()
return
}
preview := chilkat.NewEmail()
success = email.MakeCopy(preview)
if success != true {
fmt.Println(email.LastErrorText())
email.DisposeEmail()
preview.DisposeEmail()
return
}
// Keep related items: the HTML still refers to them.
preview.DropAttachments()
fmt.Println("Files in original: ", email.NumAttachments(), " Files in preview: ", preview.NumAttachments())
if preview.HasHtmlBody() != true {
fmt.Println("This message has no HTML preview.")
email.DisposeEmail()
preview.DisposeEmail()
return
}
html := chilkat.NewStringBuilder()
success = preview.GetHtmlBodySb(true,html)
if success != true {
fmt.Println(preview.LastErrorText())
email.DisposeEmail()
preview.DisposeEmail()
html.DisposeStringBuilder()
return
}
success = html.WriteFile("preview.html","utf-8",false)
if success != true {
fmt.Println("Failed: html.WriteFile.")
email.DisposeEmail()
preview.DisposeEmail()
html.DisposeStringBuilder()
return
}
fmt.Println("Saved preview.html.")
email.DisposeEmail()
preview.DisposeEmail()
html.DisposeStringBuilder()