|
The Chili!POP3 component retrieves e-mail messages from a POP3 server from an ASP script. This component has two main interfaces. The POP3 interface creates and controls the connection to a POP3 server. 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 Chili!POP3 component does not use registry settings.
The Chili!POP3 component is registered with the ProgId of "CHILI.POP3.1."
The following ASP script written in VBScript creates an instance of the component:
Set pop3 = Server.CreateObject( "CHILI.POP3.1" )
The POP3 interface creates and controls a connection to a POP3 server.
The POP3 interface exposes no properties.
· Messages
The Messages collection is a collection of Message objects, as described later in "Chili!POP3 Message Interface." This collection is read-only and does not support the standard Append or Delete collection methods.
The following methods control a network connection to a POP3 server.
· Connect
· Delete
· Disconnect
· Reset
The Connect method establishes a network connection to a POP3 server.
Arguments:
Host |
The hostname of the server with which to connect. |
UserId |
The User ID required for connecting with the server. |
Password |
The password required for connecting with the server. |
Example:
See the following Disconnect example.
The Disconnect method disconnects from the POP3 server.
Example:
Set pop3 = Server.CreateObject("CHILI.POP3.1")
pop3.Connect "mail.foo.com", "myuserid", "mypsswd"
pop3.Disconnect
The Delete method deletes a message on the POP3 server. This does not delete the message from the Messages 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, any messages that were deleted from the mailbox are restored to their un-deleted state.
Example:
Set pop3 = Server.CreateObject("CHILI.POP3.1")
pop3.Connect "mail.foo.com", "myuserid", "mypsswd"
pop3.Reset
pop3.Disconnect
The Chili!POP3 component Message interface provides access to the messages currently in the mail store on the connected server. The properties, methods, and collections of the Message object are used to access those messages.
There are varying network costs associated with accessing the 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 can 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 can be gathered without retrieving the entire message, the component first attempts the TOP command. If that command fails, the component then attempts to fulfill the property request via the full message RETR command.
(LW means it can be "lightweight" on POP3 servers supporting the TOP command.)
· From(LW)
· Subject(LW)
· Size(LW)
· DateSent(LW)
· DateReceived(LW)
· MsgId(LW)
· MsgUID(LW)
· HasAttachments(LW)
· Message
The From property is a string that indicates who sent the e-mail message.
The Subject property is a string that indicates the subject of the message. It may be Null (empty string).
The Size property indicates the total size of the current message in bytes.
The DateSent property indicates the date and time that the message was sent.
The DateReceived property indicates the date and time that the message was received.
The MsgId property indicates the message ID of the current message in the collection.
The MsgUID property indicates whether the server supports the UIDL command. It returns 0 if the server does not support this command.
The HasAttachments property provides an "educated guess" based on the message headers (to be lightweight) as to whether the message has attachments.
The Message property is a string that specifies the content of the message.
The Message interface collections are as follows:
· To(LW)
· CC(LW)
· Headers(LW)
· Attachments
The To collection is the list of e-mail addresses to which the message was sent. The collection is read-only and does not support the standard Append or Delete methods.
The CC collection is the list of e-mail addresses to which the message was sent as a carbon copy. The collection is read-only and does not support the standard Append or Delete methods.
The Attachments collection is the list of attachments to the current e-mail message, consisting of file name(s) and description(s). The collection is read-only and does not support the standard Append or Delete methods.
The Interface Headers collection is a collection of all message headers for the current e-mail message. This includes headers that are also accessible via friendly named fields or other collections, such as To, From, and DateSent. This collection can be accessed via the header name or index. This collection is read-only and does not support the standard Append or Delete methods.
· PreviewMessage
· SaveAttachments
The PreviewMessage method 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 consist entirely of binary data (which may be ascertained via the Headers collection) the first N lines of the message might not be meaningful to a human reader.
Lines |
The number of lines to return. |
The SaveAttachments method saves e-mail attachments to a specified directory on the server.
Directory path on the Server |
The complete path name to the directory on the server where attachments are to be saved. |
Note
In a shared Web hosting environment, such as an ISP, you might not know the directory structure above the document root for your virtual host. In this situation, you cannot specify an absolute path name for the file, so you must use the Server.mapPath directive instead.
Note about To, CC, and Headers
To, CC, BCC, and Headers are BSTR collections using the Count method to obtain the total number of items in the collection and the 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 that indicates the name of the header item (for example, From, To, Subject, and so forth).
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 Chili!POP3 Attachments collection of the Message object provides access to the attachments currently in an e-mail. The properties and methods of the Attachment object are used to access those attachments.
· FileName
· ContentType
· FileSize
· Base64
The FileName property is a string that indicates the name of the attachment.
The ContentType property is a string that indicates the content type of the attachment.
The FileSize property is a number that indicates the size of the attachment in bytes.
The Base64 property is a Boolean value that indicates whether the attachment is Base64 encoded.
· SaveToFile
· Read
The SaveToFile method saves the attachment on the server.
Directory |
The full directory path on the server. |
Note
In a shared Web hosting environment, such as with an Internet Service Provider, you might not know the directory structure above the document root for your virtual host. In this situation, you cannot specify an absolute path name for the file, so you must use the Server.mapPath directive instead.
The Read method reads the attachment.
Nsize |
The number of bytes to read from the attachment. This argument is optional. If missing, the entire attachment is read. |
Pbytes |
A safe array of bytes. |
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.