$home = "\\server1\dir2\dir2"
;$FSO = createobject("Scripting.FileSystemObject"
$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, "\\server2\dir1\dir2\log$month.txt",5) = 0
$w = WriteLine( 2 , "docmailer2010.kix started at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
ELSE
BEEP
? "Error opening log file: [" + @ERROR + "]"
sleep 5
EXIT
ENDIF
;main program loop
$rc = SetOption("NoMacrosInStrings","On")
$rc = SetOption("NoVarsInStrings","On")
$Docs = Split(ReadProfileString("\\server2\dir1\dir2\docmailer2010.txt","Docs","Names"),"#")
? "Elements in Docs Array: "+UBound($docs)
If UBound($docs)>=0
$Root = CreateObject("Outlook.Application")
$Session = $Root.GetNamespace("MAPI")
$DefaultProfile = Outlook
$Session.Logon($DefaultProfile)
$Folder = $Session.GetDefaultFolder(olFolderInbox)
$Folder.Display
? "Outlook Creation: "+@Error
For Each $Doc in $Docs
? "Doc: "+$Doc
$docemail = ReadProfileString("\\server2\dir1\dir2\docmailer2010.txt", $doc, "Email")
? "Email: "+$docemail
If Len($docemail)
$MailItem = $Root.CreateItem(0)
? "Root Creation: "+@Error
$MailItem.Importance = 1
$MailItem.Subject = "Reports - !!! DO NOT REPLY !!!"
$MailItem.Sender = "sender@company.org"
$MailItem.To = $docemail
$MailItem.Body = "!!! DO NOT REPLY - EMAIL IS NOT MONITORED. FOR ASSISTANCE CALL 657-5041 !!!"
$Attachments = DirList($home+"\"+$doc+"\(current month)",2)
? "Elements in Attachment Array: "+UBound($attachments)
If UBound($Attachments)>=0
For Each $Attachment in $Attachments
$MailItem.Attachments.Add($Attachment)
? "Attachment: "+@Error
Next
Endif
$MailItem.Send
? "Send: "+@Error
Endif
Next
$Root = 0
Endif