Quick PowerShell “Todo” Gmail Emailer

I put the following function in my PowerShell profile so that I can just bring up my PowerShell console and type myself a quick “todo” note that automatically gets emailed to me for later.  There are several things of note in this tiny script:

1.  Note the use of the $args variable to effectively allow the user to enter $msg parameter without quotes even if it contains whitespace.

2.  In this particular example I’m sending the email through Gmail.  smtp.gmail.com, port 587, SSL and authentication required.

3.  Check outhe $gmailcred variable, which gets set earlier in my profile.  It gets read from a secure string file.


function todo {
  param([string] $target = "work",
        [string] $msg )
  switch ($target)
  "work" { $target = "lance@3birdsmarketing.com" }
  "home" { $target = "lmrobins@gmail.com" }
  $emailFrom = "lmrobins@gmail.com"
  if ($args -ne "") {
    $msg = $msg + " " + $args
  $subject = "Todo: " + $msg
  $body = $msg
  $smtpServer = "smtp.gmail.com"  
  $smtp = new-object Net.Mail.SmtpClient($smtpServer, 587)
  $smtp.EnableSsl = $true
  $smtp.Credentials = [Net.NetworkCredential]($gmailcred)
  $smtp.Send($emailFrom, $target, $subject, $body)

Technorati Tags: ,,

Print | posted on Tuesday, October 26, 2010 1:27 PM


# Locksmith Grand Prairie

Left by poping at 2/15/2012 5:15 AM
Gravatar I definitely feel that the information supplied is highly relevant to every person . Regards .

# re: Quick PowerShell “Todo” Gmail Emailer

Left by Troubleshooting Windows 7 at 2/15/2012 7:01 AM
Gravatar Fantastic task ! Your internet page has presented me much of the facts and strategies I expected .

# re:

Left by grand falls casino at 3/9/2012 7:48 AM
Gravatar This is a fantastic website and I can not recommend you guys enough. Full of useful resource and great layout very easy on the eyes. Please do keep up this great work.

# re:

Left by casinos in hollywood at 3/21/2012 1:54 AM
Gravatar I really love the way information is presented in your post. I have added you in my social bookmark…and i am waiting for your next post.

Your comment:


Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski