POP3 to pull recent messages and leave messages on server

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

POP3 to pull recent messages and leave messages on server

Post by montanan » Tue Oct 05, 2010 9:27 pm

I'm wondering if any of the power-scripters out there have found a way to use POP3 to pull recent messages and leave messages on server.

There were some older posts about getmail.exe, but it is an older module and seems to be a bit less reliable than I'd like.

Any help on this would be great.

I found the following, but am not sure how to make it work within MS.

Code: Select all

  	
Visual Basic Sample ( Retrieve Email )

This sample demonstrates how to retrieve pop3 email in Visual Basic

Dim POP3 As Object
Dim POP3_MSG As Object

Set POP3 = Server.CreateObject("ANPOP.POPMAIN") 'create pop3 main object
Set POP3_MSG = Server.CreateObject("ANPOP.POPMSG") 'create pop3 msg object
						
Dim lRet As Long
Dim lCount As Long

lRet = POP3.Connect( "pop3.email.com", "asp", "asp.net" ) 'connecting pop3 server
If lRet = 0 Then
  lCount = POP3.GetTotalOfMails()
  For i = 1 To lCount
    POP3_MSG.RawContent = POP3.Retrieve( i )
    'Saving email to disk
    POP3_MSG.ExportFile "c:\pop3" & i & ".eml"
    'Deleting email from pop3 server
    POP3.Delete i
  Next
End If
'Cancel deletion operations
'POP3.Reset

POP3.Close


adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Oct 05, 2010 10:37 pm

Taken from the Macro Scheduler Help file

Code: Select all

RetrievePOP3>server,username,password,output_path
Not supported in Macro Scheduler Lite.

Retrieves mail from a POP3 server and stores new mail messages in the folder specified in output_path.
 

server: the name/address of the POP3 server
username: the POP3 account username
password: the POP3 account password
output_path: a local directory where message files should be stored
 

Unencoded messages and headers are stored as MSGn.TXT where n is an incremented suffix number.  e.g. MSG1.TXT, MSG2.TXT etc.  Text body parts will be stored as MSGn_BODYn.TXT and attachments will be stored as MSGn_attachment_filename

 
The command returns two variables:

 
POP3_MSGFILES: A semicolon delimited list of files downloaded.  Use Separate to explode and retrieve file count.

POP3_RESULT: Contains the last response, such as errors, returned by the server.
 

Optional variables are:

 
POP3_STATUS: Set to 0 to suppress the status window.  Default is 1.
POP3_PORT: The POP3 port number.  Default is 110.
POP3_TIMEOUT: Timeout in seconds.  Default is 5.

POP3_DELETE: Set to 1 to delete messages from the server after downloading. Default is 0.

POP3_MSGSIZELIMIT: Size limit in Kb.  Messages over this limit will not be downloaded.  Default is 0 (no size limit).

 
Abbreviation: RET

See also: SMTPSendMail

Example
 
Let>POP3_STATUS=1
Let>POP3_MSGSIZELIMIT=3
Let>POP3_TIMEOUT=5
RetrievePOP3>mail.server.com,username1,password,d:\emailfiles
MessageModal>POP3_RESULT
Separate>POP3_MSGFILES,;,MsgFiles
MessageModal>Files Downloaded: %MsgFiles_count%%CRLF%File List: %POP3_MSGFILES%

POP3_DELETE: Set to 1 to delete messages from the server after downloading. Default is 0.

.
.
.
.

montanan
Junior Coder
Posts: 49
Joined: Mon Jul 09, 2007 3:44 pm
Location: San Jose, CA

Post by montanan » Wed Oct 06, 2010 1:05 am

Thank you. I was aware of that example, however, the one thing it doesn't support is a large mailbox where we want to leave messages on the server.

Let's say there are 20,000 messages.

I can keep track of how many have been pulled so far, so let's say that is 19,970.

What I'm trying to do is efficiently download the remaining 30 locally while leaving the 20,000 on the server.

A couple of additional Macro Scheduler commands would be really useful...
- query to get # of messages on server
- download any single message by message number "n"

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Oct 06, 2010 1:41 am

... a large mailbox where we want to leave messages on the server.

Then what you need is an IMAP server NOT POP3.

POP3 was not designed to leave messages on the server, it is very inefficient for that purpose.

IMAP WAS designed to leave messages on the server.

There are many IMAP mail services on the internet available for free or very cheap.

Here is one that I personally use and it works well.
http://www.fastmail.us/

IMAP vs. POP

FastMail.FM supports IMAP access to email for all account levels. We only support POP access for Full and Enhanced users. We highly recommend that you use IMAP where possible.

POP is a very simple protocol that only allows downloading of messages from your Inbox to your local computer. Generally, once transferred, the email is then on your local computer and is removed from FastMail.FM.

IMAP is a much more advanced protocol that allows you to see all your folders on FastMail.FM, and quickly view subjects and message bodies of emails, but delay downloading of larger emails (such as those with attachments) to a later time if you want. IMAP also allows you to synchronise mail folders between your home machine and FastMail.FM on the web, so that you see the same folders and messages wherever and however you access your email.

http://www.fastmail.us/help/remote_emai ... _smtp.html
.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts