Retrieving Email from a POP Account
Description from: http://www.chilisoft.com/caspdoc/
Chili!POP3 1.1: POP3
Post Office Protocol COM object used to retrieve email from a mail server, using the same protocol used by most email clients.
The Chili!Pop3 1.1 Control enables users to retrieve messages from a POP3 server using ASP scripts. This component has two main interfaces. The first, the POP3 interface, deals with the message collection by retrieving messages and controlling messages from a POP3 server. The second interface, the Message interface, exposes all of the properties of a single message. Additional interfaces are exposed to support retrieval of message lists and message attachments.
The control makes use of no registry settings.
The Chili!Pop3 1.1 Control is registered with the ProgId of "CHILI.POP3.1". The following VBScript excerpt shows creating an instance of the control.
Set pop3 = Server.CreateObject( "CHILI.POP3.1" )
The Chili!Pop3 1.1 ActiveX Control exposes the following properties and methods.
The POP3 Interface
Properties:
The POP3 Interface exposes no properties.
Collections
Messages
Methods
Connect
Delete
Disconnect
Reset
- Property Details:
Messages
A collection of Message Objects, as described below. The collection is "read-only", and does not support the standard Append or Delete collection methods.
Connect
Establishes network connect to POP3 server.
Arguments:
Host |
Server to connect to |
UserId |
User Id to use with server to connect to |
Password |
Password to use with server to connect to |
Example:
See the Disconnect example below.
Disconnect
Disconnects from POP3 server.
Example:
Set pop3 = Server.CreateObject("CHILI.POP3.1")
pop3.Connect "mail.foo.com", "myuserid", "mypsswd"
pop3.Disconnect
Delete
Delete a message on the POP3 server. It does not delete the message from the Message collection.
Arguments:
Id |
0 based index for the message in the message collection |
Reset
Returns the POP3 server to the beginning of the transaction state (Connected) and ignores any commands and their effect on the connection. For example all mail which may have been requested to be deleted from mailbox is restored to the un-deleted state.
Example:
Set pop3 = Server.CreateObject("CHILI.POP3.1")
pop3.Connect "mail.foo.com", "myuserid", "mypsswd"
pop3.Reset
pop3.Disconnect
The Message Interface
The POP3 control's Messages collection provides access to the messages currently in the mail store on the connected server. The properties, methods and collections of the Message object described here are used to access those messages.
There are varying costs associated with accessing different properties of a message. For POP3 servers that support the optional TOP command, accessing any header information and the first few lines of the message may be accomplished without paying the data transfer overhead of moving the entire message from the server to the client. Note: when requesting any of the properties that may be gathered without retrieving the entire message the control will first try the TOP command. If that fails the control will then attempt to fulfil the property request via the full message RETR command.
Properties:
(LW = potentially "lightweight" on POP3 servers supporting TOP command).
From(LW)
Subject(LW)
Size(LW)
DateSent(LW)
DateReceived(LW)
MsgId(LW)
MsgUID(LW)
HasAttachments(LW)
Message
Collections
To(LW)
CC(LW)
Headers(LW)
Attachments
Methods
PreviewMessage
SaveAttachments
- Property Details:
From (read)
A string that indicates who sent the mail message.
Subject (read)
A string that indicates what the message may be about. May be null (empty string).
Size(read)
The total size of the current message in bytes.
DateSent(read)
The date and time that them message was sent.
DateRecieved(read)
The date and time that the message was received.
MsgId(read)
The message id of the current message in the collection.
MsgUID(read)
On servers that support the UIDL command, a unique identifier for this message. Unlike the MsgId property, the MsgUID property should not change across POP3 sessions, allowing for more efficient use of previewing and server resources. 0 if the server does not support the UIDL command.
HasAttachments(read)
An "educated guess" based on the message headers (to be lightweight) at whether or not the message has attachments.
Message (read)
The text portion of the message.
Collection Details
To
A collection of email addresses that the mail message was sent to. The collection is "read-only", and does not support the standard Append or Delete collection methods.
CC
A collection of email addresses that mail message was sent to as a carbon copy. The collection is "read-only", and does not support the standard Append or Delete collection methods.
Attachments
A collection of attachments of the current mail message, consisting of file name and description. The collection is "read-only", and does not support the standard Append or Delete collection methods.
Headers
A collection of all of the message headers for this message. Includes those headers also accessible via more friendly named fields or other collections (e.g. To, From, DateSent, etc...). May be accessed via the header name or index. The collection is "read-only", and does not support the standard Append or Delete collection methods.
Method Details
PreviewMessage
Returns the specified number of lines of the message body. For servers that support the TOP command this is performed without retrieving the entire message body. For messages with attachments or messages that are only binary data (which may be ascertained via the Headers collection) the first N lines of the message may or may not be meaningful to a human reader.
Arguments:
Lines |
The number of lines desired. |
SaveAttachments
Gets the attachment(s) out of the email and then places them in the specific directory on the server.
Arguments:
Directory path on the Server |
The full path to where to place the attachment(s) to the email as (a) file(s). |
Note: To, CC and Headers
These are all BSTR collections. Using Count method to obtain the total number of item in the collection and using Item method to obtain each item. The difference is that for To, CC and BCC, the first argument of Item is a 0 based index, while for Headers, the first argument is a string indicates the name of the header item (for example, "From", "To", "Subject", etc).
Example:
Set pop3 = Server.CreateObject("CHILI.POP3.1")
pop3.Connect "mail.foo.com", "myuserid", "mypsswd"
For each item in pop3.Messages
For each CC in Item.CC
MsgBox CC
next
next
pop3.Reset
pop3.Disconnect
The Attachment Interface
The POP3 control's Attachments collection in Message object provides access to the attachments currently in a mail. The properties, methods of the Attachment object described here are used to access those attachments.
Properties:
FileName
ContentType
FileSize
Base64
Methods
SaveToFile
Read
Property Details:
FileName (read)
A string that indicates the name of the attachment.
ContentType (read)
A string that indicates the content type of this attachment.
FileSize (read)
A number indicates the size of the attachment in byte.
Base64 (read)
A Boolean value indicates if the attachment is Base64 encoded.
Method Details
SaveToFile
Save the attachment on the server
Arguments:
Directory |
The full directory path on the server. |
Read
Save the attachment on the server.
Arguments:
Nsize |
The number of bytes to read from the attachment. This argument is optional. If missing, the whole attachment will be read. |
Pbytes |
A safearray of Byte. |
|