So that part first...
In GV settings, make sure you have enabled "Forward messages to email".
Then from GV... Send a text message to your GV number.
Head you your GMAIL account, and find that email notification from GV.
Click on the three vertical dots next to the 'reply' arrow, in this email, and select 'Show original':
This is the email address of this conversation, that you will use in your script:
The rest of this, is the script I have scheduled to run every day, telling me what my target mileage should be less than, and how many days I have left on this 39 month lease.
$ODOatStart = 18
$LeaseMileage = 325000
$LeaseStarted = "11/16/2019"
$LeaseEnding = "02/16/2023"
$DaysHad =
(((Get-date).AddDays(1))-[DateTime]'11/16/2019').Days
$TotalDays = 1189 # = ([DateTime]$LeaseEnding-[DateTime]$LeaseStarted).Days+1
$MilesPerDay = 27.33389 # = ($LeaseMileage/$TotalDays)
$MilesAllowed_Today = '{0:N0}' -f ([math]::Round(($DaysHad*$MilesPerDay)+$ODOatStart))
$Username = "joe.smith" # Just the username. Leave out the
'@gmail.com'
$PW = "sr465bblo0986vfert65z" # Application Specific PW (because of
2-factor auth)
$EmailFrom = "joe.smith@gmail.com"
#$EmailTo = 5554441313@tmomail.net
# look at the 'From:' line of the raw email
$EmailTo = "15551212.15551212.g45ty76vtrq@txt.voice.google.com"
$Subject = "Mileage Target"
$DaysLeft = '{0:N0}' -f
($TotalDays - $DaysHad)
$Body = "ODO: $MilesAllowed_Today ($DaysLeft days left)"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl
= $true
$SMTPClient.Credentials
= New-Object System.Net.NetworkCredential($Username, $PW);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
#([datetime]"02/16/2023").ToString(“dddd,
dd MMM yyyy”)
|
Some of the calculations ($TotalDays and $MilesPerDay) are commented out...
Plug in the variables, and (F8) run just those...
Then run those calculations to get their fixed values.
([DateTime]$LeaseEnding-[DateTime]$LeaseStarted).Days+1
($LeaseMileage/$TotalDays)
|
Or run the calculations each time... Your call... I don't know your life. :-)
$TotalDays =
([DateTime]$LeaseEnding-[DateTime]$LeaseStarted).Days+1
$MilesPerDay =
($LeaseMileage/$TotalDays)
|
The only reason I hard code them in, is that these are 'fixed; values, and it makes the script run just a (nominal, but still) bit faster.
You can use this to send texts to a mobile phone directly too...
The T-Mobile example is commented out.
And you can send to multiple recipients by separating addresses with a single comma, and encapsulating that in double quotes:
$OtherEmail = "5554441313@tmomail.net"
$EmailTo = "$OtherEmail,15551212.15551212.g45ty76vtrq@txt.voice.google.com"
|
~ That last line was just me looking at what day of the week the lease ends on.
No comments:
Post a Comment