Go Requires Chilkat v11.0.0+
Go
Forward an email as an attachment
See more Email Object Examples
Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.
Chilkat Go Downloads
success := false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
original := chilkat.NewEmail()
success = original.LoadEml("message.eml")
if success != true {
fmt.Println(original.LastErrorText())
original.DisposeEmail()
return
}
email := chilkat.NewEmail()
email.SetFrom("Sam Lee <sam@example.com>")
success = email.AddTo("Alex Rivera","alex@example.net")
if success != true {
fmt.Println(email.LastErrorText())
original.DisposeEmail()
email.DisposeEmail()
return
}
email.SetSubject("Forwarded message")
email.SetBody("The original email is attached.")
success = email.AttachEmail(original)
if success != true {
fmt.Println(email.LastErrorText())
original.DisposeEmail()
email.DisposeEmail()
return
}
success = email.SaveEml("forward-as-attachment.eml")
if success != true {
fmt.Println(email.LastErrorText())
original.DisposeEmail()
email.DisposeEmail()
return
}
fmt.Println("Saved forward-as-attachment.eml.")
original.DisposeEmail()
email.DisposeEmail()