PowerCat Posted February 11, 2011 Share Posted February 11, 2011 (edited) Heya I made this script over a couple of days, used at work to send out boring, repetitive emails. I could have used smtp to send emails, but this was more fun. It's designed to open and stay open. Every 4 hours it runs GetDay() to see what day today is. I need to send emails on first tuesday, second thursday and third monday. I had to be crafty to find it, plus I had to take account that @WDAY doesn't take into consideration what your windows is set for "First day of week" (monday or sunday) After every run of the email sending, it'll create a flag file to make sure that it won't run again. (are there better ways to do this??) I've been using autoit casually for about 5 years. apart form autoit and batch files, I have no other programming skills. any suggestion to improve it would be greatly appreciated! Also I hope it'll help some people learn about new functions too! expandcollapse popup#Include <Array.au3> #Include <Outlook.au3> #Include <File.au3> #include "icon.ico" #include <Misc.au3> #include <date.au3> if _Singleton("MailerDaemon",1) = 0 Then Msgbox(0,"Warning","Already running") Exit EndIf Dim $xFirstTuesday, $xSecondThursday, $xThirdMonday, $xEveryMonday, $xMonF, $xMonE, $xBCC, $xSubject, $xBCC, $xCC, $xBody, $oOutlook ;Sleep(300000) ; Collection of functions to evaluate the current day. Func GetDay() $oOutlook = _OutlookOpen() Switch @MON Case 1 $xMonF = "Janvier" $xMonE = "January" Case 2 $xMonF = "Février" $xMonE = "February" Case 3 $xMonF = "Mars" $xMonE = "March" Case 4 $xMonF = "Avril" $xMonE = "April" Case 5 $xMonF = "Mai" $xMonE = "May" Case 6 $xMonF = "Juin" $xMonE = "June" Case 7 $xMonF = "Juillet" $xMonE = "July" Case 8 $xMonF = "Aout" $xMonE = "August" Case 9 $xMonF = "Septembre" $xMonE = "Septembre" Case 10 $xMonF = "Octobre" $xMonE = "October" Case 11 $xMonF = "Novembre" $xMonE = "November" Case 12 $xMonF = "Décembre" $xMonE = "December" EndSwitch ; Find the first tuesday of every month. Select Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 6 AND @WDAY = 3 AND @MDAY <= 07 $xFirstTuesday = 1 Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 0 AND @WDAY = 2 AND @MDAY <= 07 $xFirstTuesday = 1 Case Else $xFirstTuesday = 0 EndSelect ; Find the second thursday of every month. Select Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 6 AND @WDAY = 5 AND @MDAY >= 10 AND @MDAY <= 16 $xSecondThursday = 1 Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 0 AND @WDAY = 4 AND @MDAY >= 10 AND @MDAY <= 16 $xSecondThursday = 1 Case Else $xSecondThursday = 0 EndSelect ; Find the third monday of every month Select Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 6 AND @WDAY = 2 AND @MDAY >= 14 AND @MDAY <= 20 $xThirdMonday = 1 Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 0 AND @WDAY = 1 AND @MDAY >= 14 AND @MDAY <= 20 $xThirdMonday = 1 Case Else $xThirdMonday = 0 EndSelect ; Find out if today is monday Select Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 6 AND @WDAY = 2 $xEveryMonday = 1 Case RegRead("HKEY_CURRENT_USER\Control Panel\International","iFirstDayOfWeek") = 0 AND @WDAY = 1 $xEveryMonday = 1 Case Else $xEveryMonday = 0 EndSelect EndFunc ; Send first-tuesday excel sheet email. Func FirstTuesday() $xSubject = "Altiris Pilots - Prevision for this month Patch deployment" $xCC = "" $xBCC = "powercat@gmail" $xBody = "Good morning,<br><br>As per usual, please review the Altiris Pilot list in order to validate the data.<br>Let us know of any changes that need to be done<br>Thank you.<BR><BR><BR><BR><BR><BR><BR><b>Olivier Gagnon</b>" _OutlookSendMail($oOutlook, "powercat@gmail", "", $xCC, $xBCC, $xSubject, $xBody,"\\someserver\SystemManagement\Altiris\Patch Management\List Pilots Internationnal 2010.xls",$olFormatHTML,"",@ScriptDir & "\Outlook\OutlookWarning1.exe") _FileCreate(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_FirstTuesday") EndFunc ; Send second thursday update email. Func SecondThursday() $xSubject = "Déploiment des correctifs pour " & $xMonF & " / " & $xMonE & " patch deployment." $xCC = "" $xBCC = "powercat@gmail" $xBody = "Bonjour<br><br><b>Altiris</b>: Le déploiement des correctifs sera fait Mardi le " & @MDAY + 5 & " " & $xMonF & " " & @YEAR & " à 03h00" _OutlookSendMail($oOutlook, "powercat@gmail", "", $xCC, $xBCC, $xSubject, $xBody,"",$olFormatHTML,"",@ScriptDir & "\Outlook\OutlookWarning1.exe") _FileCreate(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_SecondThursday") EndFunc ; Send second monday warning email. Func ThirdMonday() $xSubject = "Correctifs " & $xMonF & " " & @YEAR & " - Stations de travail" $xBCC = "powercat@gmail" $xCC = "" $xBody = "Bonjour,<br><br>Cette nuit débutera l'installation des correctifs sur vos postes de travail.<br>S'il vous plait nous fournir vos résultats <b>avant ce mercredi midi.</b><br><br>Merci." _OutlookSendMail($oOutlook, "powercat@gmail", "", $xCC, $xBCC, $xSubject, $xBody,"",$olFormatHTML,"",@ScriptDir & "\Outlook\OutlookWarning1.exe") _FileCreate(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_ThirdMonday") EndFunc ; Upload the new test excel sheet to the public folder by an email. Func EveryMonday() ; This will list all folders in \\it11\preprod and find the ones that are 1 week old and newer, make them into a nifty list and send it by email. $MyArray = _FileListToArray("\\it11\production\", "*", 2) local $array1[1] local $t[1] local $yyyymd local $xDate For $i = 0 to UBound($MyArray)-1 $t = FileGetTime("\\it11\production\" & $MyArray[$i], 1, 0) If Not @error Then $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2] $xDate = _DateDiff('d',$yyyymd, _NowCalcDate()) EndIf If $xDate <= 7 Then _ArrayAdd($array1, $yyyymd & " - " & $MyArray[$i]) Next _ArrayDelete($array1, 0) _ArrayDelete($array1, 0) _ArraySort($array1) $oOutlook = _OutlookOpen() $xSubject = UBound($array1) & " new Packages in production as of " & _DateAdd('d', -7, _NowCalcDate()) $xCC = "powercat@gmail" $xBCC = "" $xBody = "Please review the following list of packages that were released in prod since " &_DateAdd('d', -7, _NowCalcDate()) & ".<br>If the package not be available on your local package server, please send a request to 3551<br>and specify the requested package name for copy.<br><br>" & _ArrayToString($array1, "<br>") _OutlookSendMail($oOutlook, "powercat@gmail", "", $xCC, $xBCC, $xSubject, $xBody,"",$olFormatHTML,"","P:\Scripts\Outlook\OutlookWarning1.exe") ; end folder listing email. $oOutlook = _OutlookOpen() $xSubject = "Pilot test list as of " & $xMonE & " " & @MDAY & ", " & @YEAR & "." $xBCC = "" $xCC = "" $xBody = "Please find this updated list which contains the pilot tests around the world." _OutlookSendMail($oOutlook, "powercat@gmail", "powercat@gmail", $xCC, $xBCC, $xSubject , $xBody,"\\serverhere\SystemManagement\Altiris\Patch Management\List Pilots Internationnal 2010.xls",$olFormatHTML,"",@ScriptDir & "\Outlook\OutlookWarning1.exe") _FileCreate(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_EveryMonday") EndFunc ; Everything to evaluate on a daily basis. Func BeginDaily() If $xFirstTuesday = 1 AND FileExists(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_FirstTuesday") = 0 Then FirstTuesday() If $xSecondThursday = 1 AND FileExists(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_SecondThursday") = 0 Then SecondThursday() If $xThirdMonday = 1 AND FileExists(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_ThirdMonday") = 0 Then ThirdMonday() If $xEveryMonday = 1 AND FileExists(@AppDataDir & "\" & @MDAY & @MON & @YEAR & "_EveryMonday") = 0 Then EveryMonday() EndFunc ; evaluate conditions While 1 GetDay() BeginDaily() Sleep(10000000) WEnd Edited February 11, 2011 by PowerCat Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now