Sample code for 30+ languages & platforms
Visual Basic 6.0 Requires Chilkat v11.0.0+

Preserve the original email and save a modified copy

See more Email Object Examples

Use with-attachments.eml as a stand-in for bytes from an IMAP fetch or a message queue. Preserve those bytes first. Parse them into an Email object, add a local processing header, and serialize the result into a separate buffer. The archived input remains suitable for later byte-level inspection.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim mimeBytes As New ChilkatBinData
success = mimeBytes.LoadFile("with-attachments.eml")
If (success <> 1) Then
    Debug.Print "Failed: mimeBytes.LoadFile."
    Exit Sub
End If

success = mimeBytes.WriteFile("received-original.eml")
If (success <> 1) Then
    Debug.Print "Failed: mimeBytes.WriteFile."
    Exit Sub
End If

Dim email As New ChilkatEmail
success = email.SetFromMimeBd(mimeBytes)
If (success <> 1) Then
    Debug.Print email.LastErrorText
    Exit Sub
End If

email.AddHeaderField "X-Workflow-State","reviewed"
'  GetMimeBd appends to its destination. Use a fresh buffer for this message.
Dim rendered As New ChilkatBinData
success = email.GetMimeBd(rendered)
If (success <> 1) Then
    Debug.Print email.LastErrorText
    Exit Sub
End If

success = rendered.WriteFile("reviewed.eml")
If (success <> 1) Then
    Debug.Print "Failed: rendered.WriteFile."
    Exit Sub
End If

Debug.Print "Archived received-original.eml and saved reviewed.eml."