################################################################## ## Authors: Jonathan Perret and Gerald Lester ## ## Purpose: This sends SMTP mail ## ## Date: December 27, 1995 ## ## (mod for ESMTP server by Igor Volobouev, 03/06/02) ## ################################################################## ## Send SMTP to mail host. proc sendmail {smtphost toList from subject body {trace 0}} { if $trace then { puts stdout "Connecting to $smtphost:25" } set sockid [socket $smtphost 25] puts $sockid "MAIL From:<$from>" flush $sockid # Get whatever junk the server is throwing at us until there # is an acceptable status word. The junk may be there because # we did not use the HELO command, and the server is ESMTP # instead of just SMTP. set result "" while {1} { set tmp [gets $sockid] append result $tmp "\n" set extended_code [string range $tmp 0 3] if {[string compare [string range $extended_code end end] "-"]} { break } } if $trace then { puts stdout "MAIL From:<$from>\n\t$result" } foreach to $toList { puts $sockid "RCPT To:<$to>" flush $sockid } set result [gets $sockid] if $trace then { puts stdout "RCPT To:<$to>\n\t$result" } puts $sockid "DATA " flush $sockid set result [gets $sockid] if $trace then { puts stdout "DATA \n\t$result" } puts $sockid "From: <$from>" puts $sockid "To: <$to>" puts $sockid "Subject: $subject" puts $sockid "\n" foreach line [split $body "\n"] { puts $sockid "[join $line]" } puts $sockid "." puts $sockid "QUIT" flush $sockid set result [gets $sockid] if $trace then { puts stdout "QUIT\n\t$result" } close $sockid return; }
Notice that there are MANY other useful ways to emit e-mail, some of them reachable through the smtp and attachment pages.
peterc Note that using this proc to connect directly to mail servers that aren't under your own organisation's control will probably fail against all but the worst managed, due to the prevalence of Greylisting (http://en.wikipedia.org/wiki/Greylisting), a technique employed to reduce the impact of spam.