;****
;****
;
; Docmailer.KIX
; mail reports to certain docs
;
; Note : Reads doctor info from docmailer.txt file
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-
;setup
$cdate = "2009/03/01"
$home = "K:\Doctor Reports\"
$setup = "\\ntserver2\mis\reports\docmailer.txt"
;$FSO = createobject("Scripting.FileSystemObject")
Dim $attach [15]
;open txt file with tab names
IF Open(1, "$setup") = 0
$drfile = ReadLine(1)
ELSE
BEEP
? "Doc file not opened, error code: [" + @ERROR + "]"
sleep 5
EXIT
ENDIF
$thismo = @monthno -1
IF $thismo = 0
$month = "12"
ELSE
IF $thismo > 9
$month = CSTR($thismo)
ELSE
$month = "0" + CSTR($thismo)
ENDIF
ENDIF
$year = IIf(@MONTHNO = 1, @YEAR -1, @YEAR)
;open log file
IF Open(2, "\\ntserver2\mis\reports\log$month.txt",5) = 0
$w = WriteLine( 2 , "docmailer.kix started at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
ELSE
BEEP
? "Error opening log file: [" + @ERROR + "]"
sleep 5
EXIT
ENDIF
;main program loop
?"read "
sleep 2
WHILE $readerr = 0
$x = ReadLine(1)
$readerr = @ERROR
$folder = SUBSTR($x, 1, INSTR($x, ",")-1)
$x = SUBSTR($x, INSTR($x, ",")+1, LEN($x) - INSTR($x, ","))
$email = SUBSTR($x, 1, LEN($x) - INSTR($x, ","))
sleep 5
?"folder = $folder"
$x = 0
$FileName = Dir("$home$folder\(current month)\*.*")
While $FileName <> "" and @ERROR = 0
$file = "$home$folder\(current month)\$filename"
$fdate = Substr(GetFileTime($file),1,10)
IF $fdate > $cdate
$attach[$x] = "$filename"
$x = $x + 1
ENDIF
$FileName = Dir() ; retrieve next file
LOOP
IF $attach[0] <> ""
SendEmail ("$email", "Reports - !!! DO NOT REPLY !!!",
"!!! DO NOT REPLY - EMAIL IS NOT MONITORED. FOR ASSISTANCE CALL 657-5041 !!!",
$attach[0],
"$home$folder\(current month)\"+$attach[0],
$attach[1],
"$home$folder\(current month)\"+$attach[1],
$attach[2],
"$home$folder\(current month)\"+$attach[2],
$attach[3],
"$home$folder\(current month)\"+$attach[3],
$attach[4],
"$home$folder\(current month)\"+$attach[4],
$attach[5],
"$home$folder\(current month)\"+$attach[5],
$attach[6],
"$home$folder\(current month)\"+$attach[6],
$attach[7],
"$home$folder\(current month)\"+$attach[7],
$attach[8],
"$home$folder\(current month)\"+$attach[8],
$attach[9],
"$home$folder\(current month)\"+$attach[9],
$attach[10],
"$home$folder\(current month)\"+$attach[10],
$attach[11],
"$home$folder\(current month)\"+$attach[11],
$attach[12],
"$home$folder\(current month)\"+$attach[12],
$attach[13],
"$home$folder\(current month)\"+$attach[13],
$attach[14],
"$home$folder\(current month)\"+$attach[14])
ENDIF
ReDim $attach [15]
LOOP
$ = Close (1)
$w = WriteLine( 2 , "docmailer.kix finished at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
$w = WriteLine( 2 , " " + Chr(13) + Chr(10) )
$ = Close (2)
RETURN
Function SendEmail ($Recip, $Subject, $Text,
Optional $AttachmentName1,
Optional $AttachmentPath1,
Optional $AttachmentName2,
Optional $AttachmentPath2,
Optional $AttachmentName3,
Optional $AttachmentPath3,
Optional $AttachmentName4,
Optional $AttachmentPath4,
Optional $AttachmentName5,
Optional $AttachmentPath5,
Optional $AttachmentName6,
Optional $AttachmentPath6,
Optional $AttachmentName7,
Optional $AttachmentPath7,
Optional $AttachmentName8,
Optional $AttachmentPath8,
Optional $AttachmentName9,
Optional $AttachmentPath9,
Optional $AttachmentName10,
Optional $AttachmentPath10,
Optional $AttachmentName11,
Optional $AttachmentPath11,
Optional $AttachmentName12,
Optional $AttachmentPath12,
Optional $AttachmentName13,
Optional $AttachmentPath13,
Optional $AttachmentName14,
Optional $AttachmentPath14,
Optional $AttachmentName15,
Optional $AttachmentPath15)
;Session.Logon now uses the default MAPI profile as found in the registry.
If @INWIN = 2
; Windows 98 profile
$DefaultProfile =
ReadValue("HKEY_CURRENT_USER\Software\Microsoft\" +
"Windows Messaging Subsystem\Profiles", "DefaultProfile")
Else
; Windows 2000 profile
$DefaultProfile =
ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\" +
"CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile")
EndIf
$Session = CreateObject("MAPI.Session")
$Session.Logon($DefaultProfile)
;Create the core MAPI objects--Message and Recipient
$Message = $Session.Outbox.Messages.Add
$Recipient = $Message.Recipients.Add
;Compose the message
$Message.Subject = $Subject
$Message.Text = $Text
;Translating email address so the '@' symbol doesn't confuse
;KiXtart as being a macro.This is better than having to remember
;to Use '@@' in the Function argument, although either method will work.
If InStr ($Recip, "<unknown:") <> 0
$Recip = SubStr($Recip, 1, InStr($Recip, "<unknown:") - 1) + "@@" +
SubStr($Recip, InStr($Recip, "<unknown:") + 9, Len($Recip))
EndIf
;Select recipient
; Note: Recipient.Type values are as follows:
; 1 = To
; 2 = Cc
; 3 = Bcc
$Recipient.Name = $Recip
$Recipient.Type = 1
$Recipient.Resolve
;Creating attachment object only if arguments were supplied.
If $AttachmentName1 <> "" AND $AttachmentPath1 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName1
$Attachment.Source = $AttachmentPath1
EndIf
If $AttachmentName2 <> "" AND $AttachmentPath2 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName2
$Attachment.Source = $AttachmentPath2
EndIf
If $AttachmentName3 <> "" AND $AttachmentPath3 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName3
$Attachment.Source = $AttachmentPath3
EndIf
If $AttachmentName4 <> "" AND $AttachmentPath4 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName4
$Attachment.Source = $AttachmentPath4
EndIf
If $AttachmentName5 <> "" AND $AttachmentPath5 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName5
$Attachment.Source = $AttachmentPath5
EndIf
If $AttachmentName6 <> "" AND $AttachmentPath6 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName6
$Attachment.Source = $AttachmentPath6
EndIf
If $AttachmentName7 <> "" AND $AttachmentPath7 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName7
$Attachment.Source = $AttachmentPath7
EndIf
If $AttachmentName8 <> "" AND $AttachmentPath8 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName8
$Attachment.Source = $AttachmentPath8
EndIf
If $AttachmentName9 <> "" AND $AttachmentPath9 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName9
$Attachment.Source = $AttachmentPath9
EndIf
If $AttachmentName10 <> "" AND $AttachmentPath10 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName10
$Attachment.Source = $AttachmentPath10
EndIf
If $AttachmentName11 <> "" AND $AttachmentPath11 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName11
$Attachment.Source = $AttachmentPath11
EndIf
If $AttachmentName12 <> "" AND $AttachmentPath12 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName12
$Attachment.Source = $AttachmentPath12
EndIf
If $AttachmentName13 <> "" AND $AttachmentPath13 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName13
$Attachment.Source = $AttachmentPath13
EndIf
If $AttachmentName14 <> "" AND $AttachmentPath14 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName14
$Attachment.Source = $AttachmentPath14
EndIf
If $AttachmentName15 <> "" AND $AttachmentPath15 <> ""
$Attachment = $Message.Attachments.Add
$Attachment.Name = $AttachmentName15
$Attachment.Source = $AttachmentPath15
EndIf
;Sending the message
$Message.Send
$Session.DeliverNow
;Disconnecting MAPI Session
$Session.Logoff
;Object Cleanup
$Attachment = 0
$Recipient = 0
$Message = 0
$Session = 0
EndFunction