package require tls
package require mime
package require smtp
set userName test
ser password test
set token [::mime::initialize -canonical text/plain -string hello]
::mime::setheader $token Subject "This is a test message"
::smtp::sendmessage $token -debug 1 -usetls 1 -ports 465 -originator
te...@gmail.com -recipients "te...@gmail.com" -servers smtp.gawab.com -
username $userName -password $password
I tried with gmail and got that the service is not available. The same
account works fine with outlook
I tried with gawab.com and got "553 you have to authenticate"
I tried with are web host and again got "553 you have to authenticate"
and I doing something wrong
I cannot give you the time to help solve this particular problem, but
I can tell you what has helped me in the past:
a) use a debug proxy server between yourself and the target
b) use telnet to investigate what the remote server is doing
c) set up your own server (say postfix) and get it working to that
first
All of these are overkill if your problem is simple, but that is not
always easy to predict from the outside.
Dave
I tried debugging but it took me nowhere. I also find it strange that
such a trivial task like sending an email is so difficult with tcl.
this is totally contrary to my experience with tcl that I cannot
believe that there is something wrong in the package. I was able to
send email to my through my work place server but it is without ssl
encryption. Am I the only one that tries to send email with gmail
account using tcl? and if my code perfect, then what can be wrong?
We can't help you unless we see something, say the trace from a debug
server; I certainly do not have the time to set up a debug
environment.
Dave
Most servers want a From and a To in the mime headers.
--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
The server told you: "You have to authenticate!!" That means , you
need some lib which implements the ESMTP command "AUTH LOGIN" and send
username and pass as 8-bit encoded strings.You can use above code for
sending mails to servers ,that support "smtp-after-pop" (first you
read some mail using POP3 ,then you send.This way you don't have to
authenticate while sending mail).
But the most email servers use ESMTP, including Gmail.
P.S. look at this: http://wiki.tcl.tk/1256
Scroll down to the bottom of the page, there is an example.
set mime_msg [mime::initialize -canonical "text/plain" -encoding
"7bit" \ -string $body]
Notice the "encoding" switch.
This answer is more what I am looking for. I tried it but still gmail
does not like tcl (and I am also a bit disappointed that we do not
have a magic package that works like a modern email client)
anyway this is my code and the error I get:
proc send_email {from to subject body} {
set opts {}
lappend opts -servers smtp.gmail.com
lappend opts -ports [list 25 465]
lappend opts -username $userName
lappend opts -password $password
lappend opts -header [list "Subject" $subject]
lappend opts -header [list "From" $from]
lappend opts -header [list "To" $to]
set mime_msg [mime::initialize -canonical "text/plain" -encoding
"7bit" -string $body]
smtp::sendmessage $mime_msg {*}$opts -debug 1 -queue false -
atleastone false -usetls false
mime::finalize $mime_msg
}
using the code with debug I get:
Trying smtp.gmail.com...
<-- 220 mx.google.com ESMTP f11sm19020783wai.11
--> EHLO streamer (wait upto 300 seconds)
<-- 250-mx.google.com at your service, [59.99.176.168]
<-- 250-SIZE 35651584
<-- 250-8BITMIME
<-- 250-STARTTLS
<-- 250-ENHANCEDSTATUSCODES
<-- 250 PIPELINING
--> MAIL FROM:<mye...@gmail.com> SIZE=295 (wait upto 600 seconds)
<-- 530 5.7.0 Must issue a STARTTLS command first. f11sm19020783wai.11
--> RSET (wait upto 0 seconds)
--> QUIT (wait upto 0 seconds)
key message-id not in header
while executing
"error "key $mixed not in header""
("default" arm line 5)
invoked from within
"switch -- $key {
"" {
set result ""
foreach lower $state(lowerL) mixed $state(mixedL) {
lappend result..."
(procedure "::mime::getheader" line 7)
invoked from within
"::mime::getheader $part ${message-idL} "
invoked from within
"smtp::sendmessage $mime_msg {*}$opts -debug 1 -queue false -
atleastone false -u
setls false "
(procedure "send_email" line 21)
invoked from within
"send_email $from $to "$subject" $body
a test""
(file "checkEmail.tcl" line 82)
so... something is still wrong.
proc send_simple_message {mailTo mailFrom smtpServer subject body} {
set token [mime::initialize -canonical text/plain -string
$body]
mime::setheader $token Subject $subject
smtp::sendmessage $token \
-originator $mailFrom \
-recipients $mailTo \
-servers $smtpServer
mime::finalize $token
}
Did you do [package require tls] before doing the smtp::sendmessage ?
The exchange looks as if there's no TLS support loaded.
From http://tcllib.sourceforge.net/doc/smtp.html :
-usetls
This package supports the RFC 3207 TLS extension (3) by default
provided the tls package is available. You can turn this off with this
boolean option.
--
73 de ke9tv/2, Kevin
In the end I used Mutt email client and execed it from tcl this was
easy. In my experience tcl totally failed me. I hope one they a
package will come that will allow just:
email::send -to $to -cc $cc -subject $subject -message $message -user
$user -password $password -file $file -ssl 1
as simple as any email client.