Sample code for 30+ languages & platforms
Xojo Plugin Requires Chilkat v11.0.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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim email As New Chilkat.Email
success = email.LoadEml("text-and-html.eml")
If (success <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

Dim data As New Chilkat.BinData
success = data.AppendString("Time,Activity" + EndOfLine.Windows + "09:00,Welcome" + EndOfLine.Windows + "10:00,Field session" + EndOfLine.Windows,"utf-8")
If (success <> True) Then
    System.DebugLog("Failed: data.AppendString.")
    Return
End If

success = email.AddAttachmentBd("agenda.csv",data,"text/csv")
If (success <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

//  AddRelatedBd returns the identifier that must appear after cid: in the HTML.
Dim image As New Chilkat.BinData
success = image.AppendEncoded("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAASUlEQVR4nGMQK/ImBv3//x/CYCBSNQkaIKqJ1YCmGkUDsigu1egakOWwqsaiAaICl2p0P8DV4VKNxdP4VWMPJTyqiY04sZGuAQBhyhp6A/ap2AAAAABJRU5ErkJggg==","base64")
If (success <> True) Then
    System.DebugLog("Failed: image.AppendEncoded.")
    Return
End If

Dim cid As String
cid = email.AddRelatedBd("confirmed.png",image)
If (email.LastMethodSuccess <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

Dim html As New Chilkat.StringBuilder
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 <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

success = email.SaveEml("with-attachments.eml")
If (success <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

System.DebugLog("Saved with-attachments.eml.")