[racket] (smtp-send-message ...) with #:tls-encode
Hi Stephen,
Here you go. Here's some code adapted from one of our apps.
I actually had to hack net/smtp to get AUTH PLAIN to work against our mail server.
I omitted the changes here as I imagine it's not a common problem.
Cheers,
-- Dave
#lang scheme/base
(require (prefix-in net-head: net/head)
net/smtp
openssl)
; #:from string
; #:to string
; #:subject string
; [#:cc (U string #f)]
; [#:smtp-server string]
; [#:smtp-username string]
; [#:smtp-password string]
; string
; ->
; void
(define (send-email
#:from from
#:to to
#:cc [cc #f]
#:subject subject
#:smtp-server [smtp-server "smtp.example.com"]
#:smtp-username [smtp-username "foo"]
#:smtp-password [smtp-password "bar"]
content)
(let ([recipients (cons to (if cc (list cc) null))]
[headers (net-head:standard-message-header
from
(list to)
(if cc (list cc) null)
null ; bcc
subject)])
(smtp-send-message
smtp-server
(strip-friendly-names from)
(list* (strip-friendly-names to)
(if cc
(list (strip-friendly-names cc))
null))
headers
(regexp-split #rx"\r?\n" content)
#:auth-user smtp-username
#:auth-passwd smtp-password
#:tls-encode ports->ssl-ports)
(void)))
; Strips friendly names from an email address if present, for example:
; Dave <dave at example.com> -> dave at example.com
; dave at example.com -> dave at example.com
;
; string -> string
(define (strip-friendly-names email)
(match (regexp-match #px"^.*[<](.*)[>]$" email)
[(list _ ans) ans]
[#f email]))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110308/bb9cd456/attachment.html>