The concern is documenting sending emails from CLI which I use to quickly sending emails to myself as not to distract myself from the task-at-hand. Just type eml and write a TODO to get the idea out of your head into the mailbox.


1. Allow less secure apps


  • note that this is not allowed for 2-step verification enabled

2. Script

  • here’s the script, with hardcoded to and from, since I am sending emails to myself and using inbox as todo list
  • save a password to your Gmail account into an persistant environmental variable for your user account with
function sendEmail {
    param (
    $from = ""
    $to = ""
    $password = ConvertTo-SecureString -String $env:emailPassword -AsPlainText -Force 
    $credentials = New-Object Management.Automation.PSCredential -ArgumentList $from, $password
    $subject = Read-Host "enter TODO"
    $smtpServer = ""
    Send-MailMessage -From $from -To $to[$i] -Subject $subject -SmtpServer $smtpServer -Credential $credentials -Verbose -UseSsl -BodyAsHtml -Encoding "Unicode"
    Write-Host "the raven flew to" $to[$i];

3. sources