Codestone Ltd logo

Read all messages on a Pop3 Server and then save all the messages to disk files

// Example: CSMail JScript Example 5
// Summary: Read all messages on a Pop3 Server and then save all the messages to disk files
// Usage:   cscript exjs05.js
//          or
//          wscript exjs05.js


pop=new ActiveXObject("csmail.Pop3client");               // Create a Pop3Client Object
pop.Connect("localhost","myusername","secret");           // and connect to the server

WScript.echo("Retrieving Messages...");
pop.RetrieveMessages();                                   // Get all the messages on the server
WScript.echo("Done...");

pop.Close(true);                                          // Close the connection to the server
                                                          // (and delete the messages on the server)

WScript.echo(pop.Messages.Count);
// Now we iterate through all the messages

enunMsgs new Enumerator(pop.Messages);                  // Need an enumerator object in JScript!

for (; !enunMsgs.atEnd(); enunMsgs.moveNext()) {          // Iterate through the files
  
WScript.echo("UIDL:"+enunMsgs.item().UIDL);
  
enunMsgs.item().SaveToFile("v:\\inbox\\"+enunMsgs.item().UIDL);
                                                          
// Save the message to a suitable location
  
}