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

Preview POP3 messages and download a complete email

See more Email Object Examples

Read a short preview for each of up to five messages into an EmailBundle, print their subjects, and download the complete first entry into a separate Email. Configure a POP3 account that supports UIDL and TOP. All messages stay on the server.

Chilkat Classic ASP Downloads

Classic ASP
<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 mail = Server.CreateObject("Chilkat.MailMan")
mail.MailHost = "pop.example.com"
mail.MailPort = 995
mail.PopSsl = 1
mail.RequireSslCertVerify = 1
mail.PopUsername = "MAIL_USER"
mail.PopPassword = "MAIL_PASSWORD"
set previews = Server.CreateObject("Chilkat.EmailBundle")
'  Keep the messages and request minimal previews. Range indexes are zero-based and inclusive.
success = mail.FetchRange(1,1,0,0,4,previews)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( mail.LastErrorText) & "</pre>"
    Response.End
End If

If (previews.MessageCount = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( "There are no messages to preview.") & "</pre>"
    success = mail.Pop3EndSession()
    If (success <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( mail.LastErrorText) & "</pre>"
        Response.End
    End If

    Response.End
End If

set header = Server.CreateObject("Chilkat.Email")
i = 0
Do While (i < previews.MessageCount)
    success = previews.EmailAt(i,header)
    If (success <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( previews.LastErrorText) & "</pre>"
        Response.End
    End If

    Response.Write "<pre>" & Server.HTMLEncode( header.Uidl & "  " & header.Subject) & "</pre>"
    i = i + 1
Loop
'  A UI could use its selected row here. FetchFull uses the preview's POP3 identity.
success = previews.EmailAt(0,header)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( previews.LastErrorText) & "</pre>"
    Response.End
End If

set email = Server.CreateObject("Chilkat.Email")
success = mail.FetchFull(header,email)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( mail.LastErrorText) & "</pre>"
    Response.End
End If

success = mail.Pop3EndSession()
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( mail.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Full message: " & email.Subject & "  Files: " & email.NumAttachments) & "</pre>"

success = email.SaveEml("pop-received.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Saved pop-received.eml.") & "</pre>"

%>
</body>
</html>