[plt-scheme] sending smtp tls mail
So simple;
(require (lib "smtp.ss" "net")
(lib "dns.ss" "net")
(lib "mzssl.ss" "openssl")
(lib "head.ss" "net")
)
(printf "ssl-available? ~s~n" ssl-available?) ; just checking
(smtp-send-message
(dns-get-address (dns-find-nameserver) "smtp.gmail.com") ; server-string
"username at gmail.com" ; from-string
'("someone at else.com") ; to-list-of-strings
(insert-field "From" "spdegabrielle at gmail.com"
(insert-field "To" "someone at else.com" empty-header)) ;; header
'("This works!" "#:tcp-connect ssl-connect") ;; message-list-of-strings/bytes
#:port-no 465
#:auth-user "username" ; for gmail don't include the @gmail.com
#:auth-passwd "yourpass"
#:tcp-connect ssl-connect
;#:tls-encode ports->ssl-ports ; the other option
)
I've added it to; http://schemecookbook.org/Cookbook/NetSendEmail
Stephen
On Nov 14, 2007 12:31 AM, Stephen De Gabrielle <stephen at degabrielle.name> wrote:
> Thanks Matt - I wish I could erase that :)
>
> I'm still lost with '(ports->ssl-ports'
>
> which fails with;
> . port->ssl-ports: connect failed (error:1408F10B:SSL
> routines:SSL3_GET_RECORD:wrong version number)
>
> cheers
> s.
>
> --
>
>
> (require (lib "smtp.ss" "net")
> (lib "dns.ss" "net")
> (lib "mzssl.ss" "openssl")
> (lib "url.ss" "net")
> (lib "head.ss" "net")
> )
>
> (smtp-send-message
> (dns-get-address (dns-find-nameserver) "smtp.gmail.com") ; server-string
> "spdegabrielle at gmail.com" ; from-string
> '("spdegabrielle at gmail.com") ; to-list-of-strings
> (insert-field "From" "spdegabrielle at gmail.com" (insert-field "to"
> "spdegabrielle at gmail.com" empty-header)) ;; header
> '("test") ;; message-list-of-strings/bytes
> #:port-no 587
> #:auth-user "spdegabrielle at gmail.com"
> #:auth-passwd "xxxxxxxx"
>
> ; #:tcp-connect proc
> #:tls-encode
> (ports->ssl-ports
> (open-input-string "hello world") ;input-port
> (current-output-port) ;output-port
> #:mode 'connect
> ; [#:context context]
> #:encrypt 'tls
> #:close-original? #t
> ;[#:shutdown-on-close? shutdown?]
> ;[#:error/ssl error]
> )
> ; [port-no]
> ) ; -> void
>
--
Cheers,
Stephen
--
Stephen De Gabrielle
s.degabrielle at ucl.ac.uk
Telephone +44 (0)20 7679 5242 (x45242)
Mobile 079 851 890 45
http://www.uclic.ucl.ac.uk/annb/MaSI.html
University College London Interaction Centre
Remax House - 31/32 Alfred Place
London - WC1E 7DP