ASPPY.pop3 & ASPPY.imap

ASPPY provides built-in native support for fetching emails via POP3 and IMAP, bypassing the need for old third-party COM components.

You can create these objects either through the ASPPY namespace or via Server.CreateObject.

IMAP Client (ASPPY.imap)

<%
Dim imap, count, msg, i
Set imap = ASPPY.imap

' Or: Set imap = Server.CreateObject("ASPPY.IMAP")

imap.Connect "imap.gmail.com", 993, True
imap.Login "user@example.com", "password123"

' Select inbox in read-only mode
count = imap.Select("INBOX", True)
Response.Write "Total messages: " & count & "<br>"

' Search for unread messages
Dim unreadIds
unreadIds = imap.Search("UNSEEN")

For i = 0 To UBound(unreadIds)
    Set msg = imap.GetMessage(unreadIds(i))
    Response.Write "Subject: " & Server.HTMLEncode(msg.Subject) & "<br>"
    Response.Write "From: " & Server.HTMLEncode(msg.From) & "<br>"
    Response.Write "Body: <pre>" & Server.HTMLEncode(msg.Body) & "</pre><hr>"
Next

imap.Logout()
%>

POP3 Client (ASPPY.pop3)

<%
Dim pop3, msgCount, i, msg
Set pop3 = ASPPY.pop3

pop3.Connect "pop.gmail.com", 995, True
pop3.Login "user@example.com", "password123"

msgCount = pop3.Stat()
Response.Write "Messages in POP3 Inbox: " & msgCount & "<br>"

' Fetch the last message
If msgCount > 0 Then
    Set msg = pop3.GetMessage(msgCount)
    Response.Write "<b>" & Server.HTMLEncode(msg.Subject) & "</b><br>"
    
    ' Attachment handling
    If msg.AttachmentCount > 0 Then
        Response.Write "Has Attachments: " & msg.AttachmentNamesText
    End If
End If

pop3.Quit()
%>

Message Object Properties

Both GetMessage() routines return a Message object with the following properties:

  • UID / Seq (IMAP only)
  • From, To, Cc, Subject, Date, MessageID
  • Body (Extracted plaintext or HTML body)
  • AttachmentCount, AttachmentNamesText
  • AttachmentName(index), AttachmentSize(index), AttachmentContentType(index)
  • Header("Header-Name") - Fetches a specific header.