emailconfig script

Hi Guys,

I have adapted the below script to test for and do all required to set up and send the config of a device monthly. All you need to do is copy this into a script and name it emailconfig, change the variables at the top to match your environment and run it once, it will set up your email settings and scheduler and you will recieve an email every 28 days with the config attached

#Change the below variables to suit
:local toadd "change@me.com"
:local smtpser "ChangeMe"
:local smtpuser "ChangeMe"
:local smtppass "ChangeMe"
:local fromdom "changeme.com"
#------ Don't Edit below This Line ------------------
:local emailconf [/tool e-mail get address]
:local emailsched [/system scheduler find name="emailconfig"]
:local date [/system clock get date]
:local name [/system identity get name]
#Section below removes any Spaces from the devices identity to allow it be used as part of the email
:for i from=0 to=( [ :len $name ]-1 ) do={ 
:local tmp [ :pick $name $i ]
:if ($tmp != " ") do={ :set $newname "$newname$tmp" }
}
:set $name $newname
#------ Performs the Script Actions Below ------------------
:if ($emailconf != $smtpser) do={ /tool e-mail set address=$smtpser from="" password=$smtppass port=587 start-tls=yes user=$smtpuser }
:if ($emailsched = "") do= { /system scheduler add interval=4w name=emailconfig on-event="/system script run emailconfig" policy= ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=dec/14/2015 start-time=01:00:00 }
/export compact file=export
#delay below to allow CCR devices time to finish creating file before moving on--
:delay 10
/tool e-mail send to=$toadd from="$name@$fromdom" subject="$name Config $date" body="$name configuration file" file=export.rsc

Please bare in mind your environment will have to be set up to allow port 587 out and your smtp server to allow TLS connection