usecase

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.

send_email_as_todo

1. Allow less secure apps

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 (
        [int]$i
    )
    $from = "pkutaj@gmail.com"
    $to = "pavol@snowplowanalytics.com"
    $password = ConvertTo-SecureString -String $env:emailPassword -AsPlainText -Force 
    $credentials = New-Object Management.Automation.PSCredential -ArgumentList $from, $password
    $subject = Read-Host "enter TODO"
    $smtpServer = "smtp.gmail.com"
    Send-MailMessage -From $from -To $to[$i] -Subject $subject -SmtpServer $smtpServer -Credential $credentials -Verbose -UseSsl -BodyAsHtml -Encoding "Unicode"
    #cls
    Write-Host "the raven flew to" $to[$i];
}

3. sources