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

From: Kejia柯嘉 (w.kejia at gmail.com)
Date: Thu May 9 14:16:33 EDT 2013

thank you very much for the guide, Greg :-)

☵☯☲



2013/5/9 Greg Hendershott <greghendershott at gmail.com>:
> Slightly off-topic, and probably preaching to the choir, but:
>
> It's definitely worthwhile setting up two-factor authentication for
> your Google account.
>
> After you do so, you can generate per-application passwords (as
> Matthias mentioned). For example you'd ask Google to generate one for
> your Racket program using SMTP. You can view all your per-application
> passwords, see when they were last used, and revoke them individually.
>
> I found it was actually much easier than I imagined, to set up and to use.
>
> https://support.google.com/accounts/bin/answer.py?hl=en&answer=180744
>
>
> On Thu, May 9, 2013 at 1:03 PM, Kejia柯嘉 <w.kejia at gmail.com> wrote:
>> 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
>>>
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users


Posted on the users mailing list.