I still can't get this working. I realized that I don't need an ON SOCKOPEN event, so I took it out. I added echoes for testing, and it echoes one line, then tells me "* /echo: insufficient parameters (line 26, mail.mrc)". I'm assuming that this is because my variable has no value. It's still not sending emails or writing anything to the text file.
Code:
on *:sockread:sendmail:{
  sockread %temptext
  echo -a %temptext
  while (%temptext) {
    sockread %temptext  
    echo -a %temptext
    write mailtemp.txt %temptext
    if ($gettok(%temptext,1,32) == 220) { sockwrite -n $sockname helo $host }
    if ($gettok(%temptext,1,32) == 250) && ($left(gettok(%temptext,2,32),3) == ibm) { sockwrite -n $sockname MAIL From:MyEmailAddress }
    if ($gettok(%temptext,1,32) == Sender) && ($gettok(%temptext,4,32) == Ok) { sockwrite -n $sockname RCPT To: $+ %toaddress }
    if ($gettok(%temptext,1,32) == Recipient) && ($gettok(%temptext,4,32) == Ok) { sockwrite -n $sockname data }
    if ($gettok(%temptext,2,32) == Mail) && ($gettok(%temptext,3,32) == queued) { halt }
  }    
  else {
    sockwrite -n $sockname Subject: %subject
    sockwrite -n $sockname $crlf
    sockwrite -n $sockname %body
    sockwrite -n $sockname .
    sockwrite -n $sockname quit
    sockclose sendmail
  }
}