Geeks With Blogs

Lance's TextBox

Scott Hanselman has a little TODO batch file that he uses to quickly email himself notes from the command line. I have something similar, but mine is a PowerShell script that uses NetCmdlets. The cool thing about the send-email cmdlet in NetCmdlets is that it supports SSL as well as other email features like html mail and attachments. There are separate cmdlets for sending other types of messages like Usenet newsgroup articles, Jabber IMs (ie, Google Talk), SMS messages, SNMP traps, etc.

Here is my script:

param( [string] $target = "work",
[string] $msg )

switch ($target)
{
"work" { $target = "me@mydomain.com" }
"home" { $target = "mailto:%22%20%7B%20$target%20=%20%22@me@myotherdomain.com" }
}

send-email -from me@mydomain.com -to $target -subject ("Todo: " + $msg) -message $msg -server 10.0.1.1

And here's how I use it:

 

PS C:\> todo work "email James about AS2"                                                                               
                                                                                                                        
Server                          Recipient                                                               Success 
------                          ---------                                                               ------- 
10.0.1.1                        lancer@nsoftware.com                                                       True 
                                                                                                                        
PS C:\>                                                                            

 

If I wanted I could use the get-dns cmdlet to find out the appropriate mail server for the recipient address and send directly to that server rather than hard-coding my own.

Posted on Wednesday, February 28, 2007 9:04 AM PowerShell | Back to top


Comments on this post: NetCmdlets Command Line Emailer saves ME time

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net