DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Checkmail

02.09.2006
| 707 views |
  • submit to reddit
        
#!/usr/local/bin/wish

set host hostname.foo
set port 110
set user username
set pass password

set sock [socket $host $port]
fconfigure $sock -buffering line
puts "Connected to mail server..."
gets $sock txt
puts $sock "user $user"
puts "username..."
gets $sock txt
if {[string first -ERR $txt] > -1} {
  puts "ERROR: Invalid username!"
  exit
}
puts $sock "pass $pass"
gets $sock txt
if {[string first -ERR $txt] > -1} {
  puts "ERROR: Invalid username/password!"
  exit
}
puts $sock "stat"
gets $sock txt
puts "$txt"
set msgs [string range $txt 4 5]
set msgs [string trimright $msgs " "]
puts $sock "quit"
puts "Mailbox for $user@$host has $msgs messages"
exit