Process description:
Our clients (hospitals - about 150-200) will send to us (to known e-mail address) their reports (4 .XLS files attached to one mail message) EACH DAY.
We must get their mails, "save to" their attachments (to pre-defined folder)... and other program must create a summary report from their XLSs... ("other program" - is not my task, other programmer writes it).
My program (it runs by Win Sheduler every hour) must do that:
1) connect to mail-server;
2) logon (post login and password);
3) get mail's quantity (BTW how I can get number of NEW mails? or how I can separate NEW mail message from OLD one?);
4) read each mail message;
5) ask "you have attachements?"
6) if "yes" - get array with attachtment's filenames;
7) save (if exists) all XLSs to folder
8) goto point (4)
9) close connection.
I never tried to work with mails from HMG before. I looked to SAMPLES, looking for "*mail*.*" files. I found "\Advanced\DeleteEmail" and "\Applications\MultipleMail" samples - it helps me on start line...
Little sample (what I can do right now):
Code: Select all
public cServer, cUser, cPass, aMessages, nMsgs, i, j
cServer := "82.122.253.164"
cUser := "gripp"
cPass := "1234554321"
oSocket := TPop3():New()
// try to connect to mail server
if oSocket:Connect( alltrim(cServer) )
MsgInfo( "Yes, connection to [ " + cServer + " ] exists !!!" )
// try to login
if oSocket:Login( alltrim(cUser), alltrim(cPass) )
MsgInfo( "Yes, login as [ " + cUser + " ] exists !!!" )
// do we have mails into InBox?
aMessages := oSocket:List(.T.) // .F.
// .F. - array with subarrays: {cMsgID, val(cSize)}
// (ID and message size)
// .T. - array with subarrays: { cMsgID, val(cSize), cSubject }
// (ID, message size, subject)
nMsgs := Len(aMessages)
if nMsgs > 0
txt := "Yes, we have mails!!! Quantity = " + ;
ltrim(str( nMsgs )) + CRLF + CRLF + "ID size subject"
for i:=1 to nMsgs
txt := txt + CRLF
txt := txt + aMessages[i,1]
txt := txt + " " + str(aMessages[i,2], 8)
txt := txt + iif( len(aMessages[i])=3, ;
" subject: " + trim(aMessages[i,3]), ;
"" )
next i
MsgInfo( txt )
// get message text and show it
for i:=1 to nMsgs
txt := "Message № " + ltrim(str(i)) + CRLF + CRLF + "Message text:" + CRLF
txt := oSocket:GetMessageText( aMessages[i,1] )
MsgInfo( txt )
next i
///// 1) how to know: is it NEW message?
///// 2) how to know: this message has attachments?
///// 3) how to get attachments list (with filenames)?
///// 3) how "save to" attachments?
else
MsgInfo( "Oops... InBox is empty." )
endif
else
MsgStop( "Oops... I couldn't login (???)" )
endif
else
MsgStop( "Oops... I couldn't connect to mail-server [ " + cServer + " ] (???)" )
endif
oSocket:Close() // after work close connection (DO IT !)