WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Postie

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Email Reader


;***************************************************************************
;**
;**  Email Reader (POP3)
;**
;**
;**  NOTICE: *********** IMPORTANT [ Use at your own risk ] ***********
;**
;**  This code grabs one email at a time, displays the content in a message
;**  and DELETES the email from the mail server.
;**
;**  Press 'No' when prompted if you DO NOT want to delete the message from
;**  the mail server.
;**
;***************************************************************************

AddExtender("WWPST44I.DLL")
host="mail.mailserver.com"
fromaddr=""
userid="{username}"
password="{password}"
port=""
mailbox=""
extractfile = "msg.txt"
flags=""
title = "Email Reader"

;Define directory to store email body & attachment files
emaildir = "C:\Temp\Email\"
If !DirExist(emaildir) Then DirMake(emaildir)
DirChange(emaildir)

;Initialize values to be used in kGetMail
kInit(host,fromaddr,userid,password,port)

;Get only one email at a time AND delete it
While @TRUE
   ;Initialize variables
   header = ""
   body = ""
   ;Get first email only
   ;   Returns header
   header = kGetMail( 1, emaildir : extractfile, "", mailbox, flags )
   ;Check Header
   ;   Break from loop when no more emails available on mail server
   If header == "There are 0 messages waiting (0 bytes)":@CRLF Then Break
   ;Grab the body contents of the email message from output file
   If FileExist( emaildir : extractfile )
      body = FileGet( emaildir : extractfile )
   EndIf
   Pause( title, "[HEADER]": @CRLF : header : @CRLF : "[BODY]" : @CRLF : body )

   ;Delete output file
   FileDelete( emaildir : extractfile )

   ;*********** DELETES EMAIL FROM MAIL SERVER [ Use at your own risk ] ***********
   ret = AskYesNo( title, "Do you want to delete this message?" )
   If ret Then kGetMail( 1, "", "", "", "d" )
EndWhile
Message( title, "Finished Getting Messages" )
Exit

Article ID:   W17373
File Created: 2017:07:28:12:58:35
Last Updated: 2008:04:10:14:08:39