Classic ASP Requires Chilkat v11.0.0+
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set email = Server.CreateObject("Chilkat.Email")
success = email.LoadEml("text-and-html.eml")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
set data = Server.CreateObject("Chilkat.BinData")
success = data.AppendString("Time,Activity" & vbCrLf & "09:00,Welcome" & vbCrLf & "10:00,Field session" & vbCrLf,"utf-8")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Failed: data.AppendString.") & "</pre>"
Response.End
End If
success = email.AddAttachmentBd("agenda.csv",data,"text/csv")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
' AddRelatedBd returns the identifier that must appear after cid: in the HTML.
set image = Server.CreateObject("Chilkat.BinData")
success = image.AppendEncoded("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAASUlEQVR4nGMQK/ImBv3//x/CYCBSNQkaIKqJ1YCmGkUDsigu1egakOWwqsaiAaICl2p0P8DV4VKNxdP4VWMPJTyqiY04sZGuAQBhyhp6A/ap2AAAAABJRU5ErkJggg==","base64")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Failed: image.AppendEncoded.") & "</pre>"
Response.End
End If
cid = email.AddRelatedBd("confirmed.png",image)
If (email.LastMethodSuccess <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
set html = Server.CreateObject("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 <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
success = email.SaveEml("with-attachments.eml")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Saved with-attachments.eml.") & "</pre>"
%>
</body>
</html>