Background story (that you can safely ignore)
I have been using scheduled tasks to send myself/other people email/SMS reminder for a long time already. For example, I once used this task to send a SMS reminder to remind someone to claim her weekly Unemployment Insurance Benefit.
In the past, I only need to set the Gmail account to allow less secure app to access and the script will work wonders. Google is now stricter for allowing less secured apps. You can still configure this setting, but they will turn it off automatically after a while and will break your automation.
Now that I must use this script again, I need to first generate an App password for my device.
- If you are using personal google account, you can go ahead and skip to step 3. For G Suite users, the administrator will need to allow users to enable 2 step Verification first.
Go to your G Suite Admin console and then Security -> Settings
- To allow 2-Step Verification, check the box to allow users to turn on 2-step Verification. It is up to you (or your organization) if you want to enforce this setting. For company, it maybe wise to enforce it to enhance security.
- Now back to the user account settings and go to Security there. Enable 2-step Verification and then click on App Passwords to set one up.
- There are two drop down menu. (at least for when this guide was written) I chose “Mail” and “Windows Computer” because I will be using a Windows system and run a scheduled task to connect and send email using PowerShell.
Once we get the Gmail/Gsuite settings out of the way, we would work on the PowerShell Script.
#Defining Variables. $Date = Get-Date -f dd #this will get us the current date $Month = Get-Date -f MMMM #this will get us the current month $Year = Get-Date -f yyyy #this will get us the current year $Today = $Month + ‘ ‘ + $date + ‘, ‘ + $year $SMTPServer = "smtp.gmail.com" $Port = 587 $EmailFrom = "kenny" #replace this with the email address that you have the App Password setup. $Pwd = "password" #replace this with the actual App password that you have just setup. $EmailTo = "kenny" #replace this with the email address or the Phone number (will explain how to send a text in a moment.) You can add multiple email here, each separate by a comma “,” $Subject = "Reminder!” #replace the subject you want to put in the Email subject line. $Body = "Today is $today! Remember you need to do this!" #replace the body of the email here. $SMTPclient = New-Object Net.Mail.Smtpclient($SMTPServer, $port) $smtpclient.enableSsl = $true $SmtpClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, $Pwd); $SMTPClient.Send($From, $To, $Subject, $Body)
- On the computer that you will be running this script, open Task Scheduler and create a task. In the action tab, set Action to “Start a program” and under “Program/Script”, type in powershell. Next to “Add arguments (optional)” put in
-ExecutionPolicy -RemoteSigned -file “c:\script\reminder.ps1” -recurse
You should replace the file path with the location of your script. I will leave the rest of the config to you.
If you run the task now, you should receive an email reminder defined from the script.
To send text messages instead of an email, you will need to know the carrier the phone number is subscribed under. For example, if 123-456-7890 is under Verizon, you can put email@example.com in the $EmailTo section
Below is a list I found with the email Gateways for the more popular phone carriers in the U.S. I believe this list is correct. I can confirm T-Mobile, Verizon, and AT&T are correct because I have used them before.
- AT&T: firstname.lastname@example.org (SMS), email@example.com (MMS)
- T-Mobile: firstname.lastname@example.org (SMS & MMS)
- Verizon: email@example.com (SMS), firstname.lastname@example.org (MMS)
- Sprint: email@example.com (SMS), firstname.lastname@example.org (MMS)
- Xfinity Mobile: email@example.com (SMS), firstname.lastname@example.org (MMS)
- Virgin Mobile: email@example.com (SMS), firstname.lastname@example.org (MMS)
- Tracfone: email@example.com (MMS)
- Simple Mobile: firstname.lastname@example.org (SMS)
- Mint Mobile: email@example.com (SMS)
- Red Pocket: firstname.lastname@example.org (SMS)
- Metro PCS: email@example.com (SMS & MMS)
- Boost Mobile: firstname.lastname@example.org (SMS), email@example.com (MMS)
- Cricket: firstname.lastname@example.org (SMS), email@example.com (MMS)
- Republic Wireless: firstname.lastname@example.org (SMS)
- Google Fi (Project Fi): email@example.com (SMS & MMS)
- U.S. Cellular: firstname.lastname@example.org (SMS), email@example.com (MMS)
- Ting: firstname.lastname@example.org
- Consumer Cellular: email@example.com
- C-Spire: firstname.lastname@example.org
- Page Plus: email@example.com