For work I have to send notifications to our Large Power customers to let them know when to shed electrical load. The program is voluntary, so our company tells them when to shed load and then they are billed based on their demand during that time. To make sending notifications easier, I wrote a batch file that makes use of Blat. Blat is a fantastic command line program that can be used to send emails via an exchange server (or whatever other method you like). Check out their website for usage information. They have lots of great examples.
I send emails by having a CSV file containing columns with First Name, Last Name, Company, Email. I send the text messages the same way using the email to text features of the various carriers. For example, Verizon is very popular in our area so you can send a text message by emailing [email protected]. You can pretty easily search for other provider’s email to text formats.
The batch file does some prompting to get the proper times for control and fill in the blanks in a text message and an email. It then just loops through the entire CSV file to get the appropriate email addresses. I’m really only tracking First Name, Last Name and Company for my own benefit when adding or removing customers from the list.
@echo off :: Setting Variables set fromeMail="Your Email Name <[email protected]>" set server=-server XXX.XXX.XXX.XXX set debug=-debug -log "C:\Messages\blat.log" -timestamp set SMSList=LargePowerSMS.csv set EmailList=LargePowerEmails.csv :: Reset the Log File copy /y NUL "C:\Messages\blat.log" > NUL :: Announce what script is being started! echo This is the Large Power Text and Email Script echo. ::Set Time Variables set hour=%time:~0,2% set min=%time:~3,2% set secs=%time:~6,2% :: Set the full name of the Day of the Week SET MYDOW=%DATE:~0,3% IF %MYDOW% == Mon SET FULLDOW=Monday IF %MYDOW% == Tue SET FULLDOW=Tuesday IF %MYDOW% == Wed SET FULLDOW=Wednesday IF %MYDOW% == Thu SET FULLDOW=Thursday IF %MYDOW% == Fri SET FULLDOW=Friday IF %MYDOW% == Sat SET FULLDOW=Saturday IF %MYDOW% == Sun SET FULLDOW=Sunday :: Set the full name of the Month set month=%date:~4,2% IF %month%== 01 SET fullmonth=January IF %month%== 02 SET fullmonth=February IF %month%== 03 SET fullmonth=March IF %month%== 04 SET fullmonth=April IF %month%== 05 SET fullmonth=May IF %month%== 06 SET fullmonth=June IF %month%== 07 SET fullmonth=July IF %month%== 08 SET fullmonth=August IF %month%== 09 SET fullmonth=September IF %month%== 10 SET fullmonth=October IF %month%== 11 SET fullmonth=November IF %month%== 12 SET fullmonth=December ::set the day of the month set day=%date:~7,2% ::set the year set year=%date:~-4% :: Ask user if Status is Code Green or Code Red :SetStatus echo Please Choose the current load control status: echo [1] Code Green echo [2] Code Red echo [3] Exit Program set /p status=Please Select 1, 2 or 3: echo. if /i "%status:~,1%" EQU "1" goto CheckStatusInput if /i "%status:~,1%" EQU "2" goto CheckStatusInput if /i "%status:~,1%" EQU "3" goto CheckStatusInput echo Please Type 1, 2 or 3. echo. goto SetStatus :CheckStatusInput if /i "%status:~,1%" EQU "1" echo You have chosen Code Green. if /i "%status:~,1%" EQU "2" echo You have chosen Code Red. if /i "%status:~,1%" EQU "3" echo You have chosen to exit the program. set /p verifystatus=Is this correct? (Y/N) echo. if /i "%verifystatus:~,1%" EQU "Y" goto StatusVerified if /i "%verifystatus:~,1%" EQU "N" goto SetStatus echo Please Type Y or N. echo. goto CheckStatusInput :StatusVerified if /i "%status:~,1%" EQU "1" goto CodeGreen if /i "%status:~,1%" EQU "2" goto CodeRed if /i "%status:~,1%" EQU "3" goto QuitProgram :CodeRed set /p defaulttimes=Use default times of 4:00 PM to 8:00 PM? (Y/N) if /i "defaulttimes:~,1%" EQU "N" goto AskTimes if /i "%defaulttimes:~,1%" EQU "Y" goto DefaultStartStopTime echo Please Type Y or N. echo. goto CodeRed :DefaultStartStopTime set starttime=4:00 PM set stoptime=8:00 PM goto CheckTimes :AskTimes set /p starttime=What time does control start? set /p stoptime=What time does control stop? echo. :CheckTimes echo You have the start time set as %starttime% echo You have the stop time set as %stoptime% echo. set /p verifytimes=Is this correct? (Y/N) echo. if /i "%verifytimes:~,1%" EQU "Y" goto TimeVerified if /i "%verifytimes:~,1%" EQU "N" goto AskTimes echo Please Type Y or N. echo. goto CheckTimes :TimeVerified :: Create a text file containing the Code Red SMS Message echo Large Power Account, Please shed electrical load during the following time period: %starttime% to %stoptime% for today, %fullmonth% %day%, %year% > "C:\Messages\LPCodeRedSMS.txt" for /F "delims=, tokens=4" %%A in (%SMSList%) DO ( "C:\Program Files\blat3217\full\blat.exe" "C:\Messages\LPCodeRedSMS.txt" -to %%A -f %fromeMail% %server% %debug% ) :: Set the subject of the email and the file containing the email body set subj=-s "Load Control Code Red for %month%/%day%/%year%, %hour%:%min%" set emailbody=LPCodeRedEmail.txt :: Create a text file for Code Red Message for today :: empty the email file so that today's will start fresh copy /y NUL %emailbody% > NUL echo Dawson Public Power District >> %emailbody% echo P.O. Box 777 >> %emailbody% echo Lexington NE 68850 >> %emailbody% echo 308-324-2386 ^| Fax: 308-324-3690 ^| http://dawsonpower.com/ >> %emailbody% echo. >> %emailbody% echo TO: Large Power Load Management Account >> %emailbody% echo FROM: Dawson Public Power District >> %emailbody% echo. >> %emailbody% echo DATE: %FULLDOW%, %fullmonth% %day%, %year% >> %emailbody% echo TIME: %hour%:%min%:%secs% >> %emailbody% echo. >> %emailbody% echo Please shed electrical load during the following time period for today, %FULLDOW%, %fullmonth% %day%, %year%: >> %emailbody% echo. >> %emailbody% echo Beginning Time: %starttime% >> %emailbody% echo Ending Time: %stoptime% >> %emailbody% echo. >> %emailbody% echo Due to electrical peak demands, on peak billing rates will be in effect during the above listed time period. Demands established during this period may be used to determine this month’s and the next 11 month’s electric bill. Therefore, the more you can reduce electric demand, the more you can save. >> %emailbody% echo. >> %emailbody% echo If conditions change or if control is waived prior to the ending time, we will provide another message. You can also monitor the status via the internet at http://dawsonpower.com/category/large-power/ >> %emailbody% echo. >> %emailbody% echo Thank You. >> %emailbody% echo. >> %emailbody% echo. >> %emailbody% echo To Unsubscribe, please reply to this email. >> %emailbody% :: End of email generation :: Send the email for /F "delims=, tokens=4" %%A in (%EmailList%) DO ( "C:\Program Files\blat3217\full\blat.exe" "C:\Messages\LPCodeRedEmail.txt" -to %%A -f %fromeMail% %subj% %server% %debug% ) goto QuitProgram :CodeGreen :: Create a text file containing the Code Green SMS Message echo Large Power Account, There is No Control for today, %fullmonth% %day%, %year% > "C:\Messages\LPCodeGreenSMS.txt" ::Send the SMS messages for /F "delims=, tokens=4" %%A in (%SMSList%) DO ( "C:\Program Files\blat3217\full\blat.exe" "C:\Messages\LPCodeGreenSMS.txt" -to %%A -f %fromeMail% %server% %debug% ) :: Set the subject of the email and the file containing the email body set subj=-s "Load Control Code Green for %month%/%day%/%year%, %hour%:%min%" set emailbody=LPCodeGreenEmail.txt :: Create a text file for Code Green Message for today :: empty the email file so that today's will start fresh copy /y NUL %emailbody% > NUL echo Dawson Public Power District >> %emailbody% echo P.O. Box 777 >> %emailbody% echo Lexington NE 68850 >> %emailbody% echo 308-324-2386 ^| Fax: 308-324-3690 ^| http://dawsonpower.com/ >> %emailbody% echo. >> %emailbody% echo TO: Large Power Load Management Account >> %emailbody% echo FROM: Dawson Public Power District >> %emailbody% echo. >> %emailbody% echo DATE: %FULLDOW%, %fullmonth% %day%, %year% >> %emailbody% echo TIME: %hour%:%min%:%secs% >> %emailbody% echo. >> %emailbody% echo Dawson Power has no Control Hours for today, %FULLDOW%, %fullmonth% %day%, %year% >> %emailbody% echo. >> %emailbody% echo Due to electrical peak demands, on peak billing rates will be in effect during the above listed time period. Demands established during this period may be used to determine this month’s and the next 11 month’s electric bill. Therefore, the more you can reduce electric demand, the more you can save. >> %emailbody% echo. >> %emailbody% echo If conditions change or if control is waived prior to the ending time, we will provide another message. You can also monitor the status via the internet at http://dawsonpower.com/category/large-power/ >> %emailbody% echo. >> %emailbody% echo Thank You. >> %emailbody% echo. >> %emailbody% echo. >> %emailbody% echo To Unsubscribe, please reply to this email. >> %emailbody% :: End of email generation :: Send the email for /F "delims=, tokens=4" %%A in (%EmailList%) DO ( "C:\Program Files\blat3217\full\blat.exe" "C:\Messages\LPCodeGreenEmail.txt" -to %%A -f %fromeMail% %subj% %server% %debug% ) :QuitProgram exit /b
This code will generate a text message for a “Code Green Day” (No Control) that looks like this:
Large Power Account, There is No Control for today, June 28, 2017
It will generate a “Code Red Message” that looks like this:
CODE RED: Large Power Account, Please shed electrical load during the following time period: 4:00 PM to 8:00 PM for today, Tuesday, June 27, 2017
It will generate an email that looks like this for “Code Green Days”:
Dawson Public Power District P.O. Box 777 Lexington NE 68850 308-324-2386 | Fax: 308-324-3690 | http://dawsonpower.com/ TO: Large Power Load Management Account FROM: Dawson Public Power District DATE: Wednesday, June 28, 2017 TIME: 8:22:17 Dawson Power has no Control Hours for today, Wednesday, June 28, 2017 Due to electrical peak demands, on peak billing rates will be in effect during the above listed time period. Demands established during this period may be used to determine this month’s and the next 11 month’s electric bill. Therefore, the more you can reduce electric demand, the more you can save. If conditions change or if control is waived prior to the ending time, we will provide another message. You can also monitor the status via the internet at http://dawsonpower.com/category/large-power/ Thank You. To Unsubscribe, please reply to this email.
It will generate an email that looks like this for “Code Red Days”:
Dawson Public Power District P.O. Box 777 Lexington NE 68850 308-324-2386 | Fax: 308-324-3690 | http://dawsonpower.com/ TO: Large Power Load Management Account FROM: Dawson Public Power District DATE: Tuesday, June 27, 2017 TIME: 8:33:52 Please shed electrical load during the following time period for today, Tuesday, June 27, 2017: Beginning Time: 4:00 PM Ending Time: 8:00 PM Due to electrical peak demands, on peak billing rates will be in effect during the above listed time period. Demands established during this period may be used to determine this month’s and the next 11 month’s electric bill. Therefore, the more you can reduce electric demand, the more you can save. If conditions change or if control is waived prior to the ending time, we will provide another message. You can also monitor the status via the internet at http://dawsonpower.com/category/large-power/ Thank You. To Unsubscribe, please reply to this email.
Hopefully somebody finds this code useful out there. I used to use a very similar batch file to generate messages for Irrigation Customers but we have since employed a developer to do a much more elegant messaging service so that customers can sign themselves up using the Dawson Power website and opt out of messages using embedded links.
If there’s something I could be doing better, I’d love to hear suggestions on this one! For now the code seems to be working well but I’m sure there is room for improvement.