Forums

Discuss all things Remember The Milk.

Sending tasks from the command line (Windows PowerShell)

we.kanes says:
Found this script today: http://poshcode.org/108

I tweaked it a bit and debugged some problems sending (didn't like Gmail's smtp server, had to use my ISP's), the end result is below. This allows me to very quickly and easily send tasks to RTM from the command line. This same concept can be applied, obviously, to any OS/scripting language. I look forward to using it while at work so tasks don't slip my mind.

What I love about it is that I can specify any of the attributes, only a few, or none of the attributes (except name of course). I also auto-tag each one with an "emailed" tag since RTM doesn't support searching the "Sent From" field.

Contents (keep in mind, the forum strips out all of my leading whitespace):

#——————————————————————————
# Func/Sub Name: Send-RTMTask
# Purpose: Sends a task to the Remember The Milk system via email.
# Arguments Supplied:
# Return Value:
# External Reference:
#——————————————————————————
function RTM
{
param([string]$Name=$(Throw "Task needs a name!"),
[int]$Priority,
[string]$Due,
[string]$Repeat,
[string]$Estimate,
[string]$Tags,
[string]$Location,
[string]$URL,
[string]$List,
[string]$Notes
)
Begin
{
# Some Constants
$RTMEmailAddress = "xxxx@rmilk.com"
$FromEmailAddress = "something@somethinglikegmail.com"
$SMTPServer = "smtp.comcast.net" #"smtp.gmail.com:465" - from home, has to be ISP's SMTP server
$MailClient = New-Object System.Net.Mail.SmtpClient($SMTPServer)
}
Process
{
$FromEmail = New-Object System.Net.Mail.MailAddress($FromEmailAddress )
$ToEmail = New-Object System.Net.Mail.MailAddress($RTMEmailAddress )
$MailMessage = New-Object System.Net.Mail.MailMessage( $FromEmail, $ToEmail)
$MailMessage.Subject = $Name

$Body = ""
if ( $Priority -ne $null ) { $Body += "P: $Priority`n" }
if ( $Due -ne $null ) { $Body += "D: $Due`n" }
if ( $Repeat -ne $null ) { $Body += "R: $Repeat`n" }
if ( $Estimate -ne $null ) { $Body += "E: $Estimate`n" }
if ( $Tags -ne $null ) { $Body += "S: emailed $Tags`n" } #add emailed for "audit trail" of emailed tasks
else { $Body += "S: emailed`n" }
if ( $Location -ne $null ) { $Body += "O: $Location`n" }
if ( $URL -ne $null ) { $Body += "U: $URL`n" }
if ( $List -ne $null ) { $Body += "L: $List`n" }
if ( $Notes -ne $null ) { $Body += "--- `n $Notes" }
$MailMessage.Body = $Body
$MailClient.Send($MailMessage)
}
End
{
}
}
Posted at 7:15am on March 8, 2009
Log in to post a reply.