Tk Library Source Code

Artifact [71b35cfa9c]
Login

Artifact 71b35cfa9ceb9b963b6eb0d7b987b4f52844d5e4:

Attachment "smtp_error_code_snippet.txt" to ticket [1376323fff] added by andreas_kupries 2005-12-09 00:09:29.
package require smtp
package require mime

#---------------------------------------------------------------- winSendMail
#
# Sends email to the specified list of addresses
#
# INPUT:	to	- A list of email addrs of the primary recipients
#		cc	- A list of email addrs of BCC recipients
#		bcc	- A list of email addrs of BCC recipients
#		subj	- The subject line
#		body	- The message body (if this string looks like a
#		file	- Flag; 0 if body is just text, 1 if body is path to file
#
# RETURN:	1 - Send failed
#		0 - Send succeeded
#
# PUBLIC
#
proc winSendMail { to cc bcc subject body { file 0 } } {
    
  global TtMailBox

  if { $file } { set filename $body; set body [ readFile $body ] }
  
  set server    <hidden>
  set user      <hidden>
  set passwd    <hidden>
  set fullname  <hidden>
  set emailaddr <hidden>
    
  set token [ mime::initialize -canonical text/plain -string $body ]

  mime::setheader   $token Subject $subject
  mime::setheader   $token Date [clock format [clock seconds] -format "%a, %d %b %Y %H:%M:%S -0800"]
  if { $cc  != "" } { mime::setheader   $token cc $cc -mode append }
  if { $bcc != "" } { mime::setheader   $token bcc $bcc -mode append }
  
  set unmailed [ smtp::sendmessage $token -recipients $to -servers $server -username $user -password $passwd -originator "\"$fullname\" <$emailaddr>" ]
		
  mime::finalize    $token

  if { $unmailed != "" } { set TtMailBox(ERROR) $unmailed; return 1 }

  return 0

}