[racket] how to use ``smtp-send-message''?

From: Kejia柯嘉 (w.kejia at gmail.com)
Date: Thu May 9 13:03:19 EDT 2013

thanks a lot for your helps. the following is my code for archiving:
``
#! /usr/local/bin/racket

#lang racket

(require net/dns)
(require net/head)
(require net/smtp)
(require openssl/mzssl)

(smtp-send-message
 (dns-get-address (dns-find-nameserver) "smtp.gmail.com")
 "senderx at gmail.com"
 '("recipientx at hotmail.com")
 (standard-message-header
  "X Sender <senderx at gmail.com>"
  '("X Recipient <recipientx at hotmail.com>")
  '() ; CC
  '() ; BCC
  "saying hello")
 '("hello world!")
 #:port-no 465
 #:auth-user "senderx"
 #:auth-passwd "thesenderxpassword"
 #:tcp-connect ssl-connect)
''

--------------
daniel

☵☯☲



2013/5/8 Matthias Felleisen <matthias at ccs.neu.edu>:
>
> I have used the script below to send email to my students via gmail:
>
> #! /bin/sh
> #|
> exec racket -t "$0" ${1+"$@"}
> |#
>
> #lang racket
>
> ;; -----------------------------------------------------------------------------
> ;; send graded solutions located in _directory_ and label them _subject_
>
> (define directory "PCode/")
>
> ;; -----------------------------------------------------------------------------
> (require net/smtp net/dns openssl/mzssl net/head)
>
> (define subject "grade for final project, take 2")
>
> (define (main)
>   (parameterize ([current-directory directory])
>     (for ((f (directory-list)) #:when (regexp-match "\\.rkt" (path->string f)))
>       (define c (file->lines f))
>       (displayln `(doing ,f ,(second c)))
>       (define to (string-split (substring (second c) 3) ", "))
>       ; (displayln `(running ,f ,to))
>       (send to (list* "" "*** do not reply to this message ***" "" c))
>       (printf "done: ~a\n" f))))
>
> (define (send to file)
>   (smtp-send-message
>    (dns-get-address (dns-find-nameserver) "smtp.gmail.com")
>    "matthias at ccs.neu.edu"
>    to
>    (standard-message-header "matthias at ccs.neu.edu" to '() '("matthias at ccs.neu.edu") subject)
>    file
>    #:port-no 465
>    ; for gmail don't include the @gmail.com
>    #:auth-user "matthias.f@"
>    #:auth-passwd "XYZ XYZ" ; gmail special password that bypasses dual verification
>    #:tcp-connect ssl-connect))
>
> ;; http://en.wikipedia.org/wiki/MIME#Multipart_messages
> ;; attaching files?
>
> (module+ main (main))
>
>
> On May 8, 2013, at 8:39 PM, Kejia柯嘉 wrote:
>
>> hello all,
>>
>> i am trying to use ``smtp-send-message" to send emails via gmail. my
>> code is following:
>> ``
>> #! /usr/local/bin/racket
>>
>> #lang racket
>>
>> (require net/head net/smtp)
>>
>> (smtp-send-message
>> "smtp.gmail.com"
>> "w1 <theuser at gmail.com>"
>> '("w2 <w2 at hotmail.com>")
>> (standard-message-header
>>  "w1 <theuser at gmail.com>"
>>  '("w2 <w2 at hotmail.com>")
>>  '() ; CC
>>  '() ; BCC
>>  "Subject")
>> '("Hello World!")
>> #:port-no 587
>> #:auth-user "theuser at gmail.com"
>> #:auth-passwd "theauthpassword")
>> ''
>> the code does not work. the similar config works for a python program.
>> anyone knows how to do this job with racket?
>>
>> ----------------------
>> daniel
>>
>> ☵☯☲
>>
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
>


Posted on the users mailing list.