Call me...

Sunday, November 17, 2019

Powershell sending to Google Voice, and also a Lease mileage tool...

Probably, the most useful part of this, is what it takes to send an email to a (your?, some other?) Google Voice (GV) conversation... I suppose.

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':

Scroll down to find the 'From:' line...
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 ''
$PW = "sr465bblo0986vfert65z" # Application Specific PW (because of 2-factor auth)
$EmailFrom = "joe.smith"
#$EmailTo =
# look at the 'From:' line of the raw email
  $EmailTo = ""
$Subject = "Mileage Target"
$DaysLeft = '{0:N0}' -f ($TotalDays - $DaysHad)
$Body = "ODO: $MilesAllowed_Today  ($DaysLeft days left)"

$SMTPServer = ""
$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.


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 = ""
$EmailTo = "$OtherEmail," 

~ That last line was just me looking at what day of the week the lease ends on.

No comments:

Post a Comment