Sample code for 30+ languages & platforms
B4X Requires Chilkat v11.0.0+

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 B4X Downloads

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim original As ChilkatEmail
original.Initialize
success = original.LoadEml("message.eml")
If success <> True Then
    Log(original.LastErrorText)
    Return
End If

Dim email As ChilkatEmail
email.Initialize
email.From = "Sam Lee <sam@example.com>"
success = email.AddTo("Alex Rivera", "alex@example.net")
If success <> True Then
    Log(email.LastErrorText)
    Return
End If

email.Subject = "Forwarded message"
email.Body = "The original email is attached."
success = email.AttachEmail(original)
If success <> True Then
    Log(email.LastErrorText)
    Return
End If


success = email.SaveEml("forward-as-attachment.eml")
If success <> True Then
    Log(email.LastErrorText)
    Return
End If

Log("Saved forward-as-attachment.eml.")