Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.0
Add an attachment and an inline image
See more Email Object Examples
Add a file attachment from memory and embed an image in the HTML body using its Content-ID. Start with any email that has an HTML body, or use text-and-html.eml from the preceding example. Save the result as with-attachments.eml.
Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim email As New ChilkatEmail
success = email.LoadEml("text-and-html.eml")
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
Dim data As New ChilkatBinData
success = data.AppendString("Time,Activity" & vbCrLf & "09:00,Welcome" & vbCrLf & "10:00,Field session" & vbCrLf,"utf-8")
If (success <> 1) Then
Debug.Print "Failed: data.AppendString."
Exit Sub
End If
success = email.AddAttachmentBd("agenda.csv",data,"text/csv")
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
' AddRelatedBd returns the identifier that must appear after cid: in the HTML.
Dim image As New ChilkatBinData
success = image.AppendEncoded("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAASUlEQVR4nGMQK/ImBv3//x/CYCBSNQkaIKqJ1YCmGkUDsigu1egakOWwqsaiAaICl2p0P8DV4VKNxdP4VWMPJTyqiY04sZGuAQBhyhp6A/ap2AAAAABJRU5ErkJggg==","base64")
If (success <> 1) Then
Debug.Print "Failed: image.AppendEncoded."
Exit Sub
End If
Dim cid As String
cid = email.AddRelatedBd("confirmed.png",image)
If (email.LastMethodSuccess <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
Dim html As New ChilkatStringBuilder
success = html.Append("<p><img alt='Confirmed' src=""cid:")
success = html.Append(cid)
success = html.Append("""></p>")
success = html.Append(email.GetHtmlBody())
success = email.AddHtmlAlternativeBody(html.GetAsString())
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
success = email.SaveEml("with-attachments.eml")
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
Debug.Print "Saved with-attachments.eml."