maildemo.tcl

Go to the documentation of this file.
00001 /*  maildemo.tcl - Copyright (C) 2005 Pat Thoyts <patthoyts@users.sf.net>*/
00002 /*  */
00003 /*  This program illustrates the steps required to compose a MIME message and */
00004 /*  mail it to a recipient using the tcllib mime and smtp packages.*/
00005 /* */
00006 /*  If we can find suitable environment variables we will authenticate with a*/
00007 /*  server (if it presents this option) and we will use SSL communications*/
00008 /*  if available.*/
00009 /* */
00010 /*  $Id: maildemo.tcl,v 1.2 2005/10/07 00:30:13 patthoyts Exp $*/
00011 
00012 package require mime
00013 package require smtp
00014 
00015 /*  The use of SSL by our client can be controlled by a policy procedure. Using*/
00016 /*  this we can specify that we REQUIRE SSL or we can make SSL optional.*/
00017 /*  This procedure should return 'secure' to require SSL*/
00018 /* */
00019 ret  policy (type demoarg , type code , type diagnostic) {
00020     if {$code > 299} {
00021         puts stderr "TLS error: $code $diagnostic"
00022     }
00023     #return secure;                      # fail if no TLS
00024     return insecure;
00025 }
00026 
00027 /*  Setup default sender and target*/
00028  DEFUSER =  tcllib-demo@[info host]
00029  USERNAME =  $tcl_platform(user)
00030  PASSWORD =  ""
00031 
00032 /*  Try and lift authentication details from the environment.*/
00033 if {[info exists env(USERNAME)]} {
00034      USERNAME =  $env(USERNAME)
00035 }
00036 
00037 /*  We can get the password from http_proxy_pass - maybe.*/
00038 if {[info exists env(http_proxy_pass)]} {
00039      PASSWORD =  $env(http_proxy_pass)
00040 }
00041 
00042  defmsg =  "This is a default tcllib demo mail message."
00043 
00044 /*  Compose and send a message. Command parameters can override the settings */
00045 /*  discovered above.*/
00046 /* */
00047 ret  Send [list \
00048                [list server localhost] \
00049                [list port 25] \
00050                [list from $DEFUSER] \
00051                [list to   $DEFUSER] \
00052                [list msg  $defmsg]] (
00053     type set , type tok [, type mime::, type initialize -, type canonical , type text/, type plain -, type string $, type msg]
00054     , type set , type args [, type list \
00055                   -, type debug 1 \
00056                   -, type servers   [, type list $, type server] \
00057                   -, type ports     [, type list $, type port] \
00058                   -, type usetls    1 \
00059                   -, type tlspolicy [, type list , type policy $, type tok] \
00060                   -, type header    [, type list , type From "$, type from"] \
00061                   -, type header    [, type list , type To "$, type to"] \
00062                   -, type header    [, type list , type Subject ", type RFC 2554 , type test"] \
00063                   -, type header    [, type list , type Date "[, type clock , type format [, type clock , type seconds]]"]]
00064     , type if , optional [info =exists ::USERNAME] =&& [string =length $::USERNAME] => 0 , optional 
00065         lappend =args \
00066             =-username  $::USERNAME =\
00067             -password  =$::PASSWORD
00068     
00069 
00070     , type eval [, type linsert $, type args 0 , type smtp::, type sendmessage $, type tok]    
00071     , type mime::, type finalize $, type tok
00072 )
00073 
00074 if {!$tcl_interactive} {
00075     eval [linsert $argv 0 Send]
00076 }

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1