Version 14 of smtp

Updated 2005-02-20 04:26:02 by CMCc

Documentation can be found at http://tcllib.sourceforge.net/doc/smtp.html


Here's a minimal useful example:

      proc send_simple_message {recipient email_server subject body} {
          package require smtp
          package require mime

          set token [mime::initialize -canonical text/plain -string $body]
          mime::setheader $token Subject $subject
          smtp::sendmessage $token \
                  -recipients $recipient -servers $email_server
          mime::finalize $token
      }

      send_simple_message [email protected] localhost \
                "This is the subject." "This is the message."

OK, this is more minimal:

         ...
      set token [mime::initialize -canonical text/plain -string $body]
      smtp::sendmessage $token \
              -header [list Subject $subject] \
              -header [list To $recipient]
      mime::finalize $token
         ...

This last one didn't work for me; I kept getting an error from sendmessage about { } not being a valid option. -- WHD.

WHD, CL will make a point of returning in July 2002 to address this error. What's above certainly worked with ... well, *some* version.

See also http://www.magma.ca/~glennj/tcl/mutt_sendmail.tcl.txt


PT 8-July-2004: Here is a rather more complex example that can handle an authenticating SMTP server.

 set tok [mime::initialize -canonical text/plain -string $TEXT]
 smtp::sendmessage $tok \
        -servers [list $SERVER] -ports [list $PORT] \
        -usetls 1 \
        -username $USERNAME \
        -password $PASSWORD \
        -header [list From "$FROM"] \
        -header [list To "$TO"] \
        -header [list Subject "$SUBJECT"] \
        -header [list Date "[clock format [clock seconds]]"]    
 mime::finalize $tok

Note: if you have trouble with sending mail, adding -debug 1 as an option to the [sendmessage] command will log the SMTP conversation and may help diagnose problems.


SV: See also SMTP with attachments


CMcC: I have put together a first cut asynchronous SMTP server here [L1 ] ... I'd be interested to see if it works for people.


Category Package, subset Tcllib