Adding support for file attachments.

master 2.0.1
Thomas Hintz 9 years ago
parent 70acb4f60f
commit 6ea2abba7d

@ -2,4 +2,5 @@
(uri targz "https://github.com/ThomasHintz/chicken-scheme-{egg-name}/tarball/{egg-release}") (uri targz "https://github.com/ThomasHintz/chicken-scheme-{egg-name}/tarball/{egg-release}")
(release "1") (release "1")
(release "2") (release "2")
(release "2.0.1")

@ -35,7 +35,7 @@
send-mail) send-mail)
(import scheme chicken) (import scheme chicken)
(use http-client uri-common intarweb json srfi-1 srfi-18) (use data-structures http-client uri-common intarweb json srfi-1 srfi-18)
(define api-user (make-parameter "")) (define api-user (make-parameter ""))
(define api-key (make-parameter "")) (define api-key (make-parameter ""))
@ -44,7 +44,7 @@
(vector->list (with-input-from-request (vector->list (with-input-from-request
(make-request method: method uri: (uri-reference url)) parameters json-read))) (make-request method: method uri: (uri-reference url)) parameters json-read)))
(define (send-mail #!key (subject #f) (text #f) (html #f) (from #f) (from-name #f) (to #f) (reply-to #f) (api-user (api-user)) (api-key (api-key))) (define (send-mail #!key (subject #f) (text #f) (html #f) (from #f) (from-name #f) (to #f) (reply-to #f) (api-user (api-user)) (api-key (api-key)) files)
(if (and subject (or text html) from from-name to reply-to) (if (and subject (or text html) from from-name to reply-to)
(rest-action "https://sendgrid.com/api/mail.send.json" 'POST (rest-action "https://sendgrid.com/api/mail.send.json" 'POST
`((api_user . ,api-user) `((api_user . ,api-user)
@ -54,6 +54,16 @@
(replyto . ,reply-to) (replyto . ,reply-to)
,(if html `(html . ,html) `(text . ,text)) ,(if html `(html . ,html) `(text . ,text))
(from . ,from) (from . ,from)
(fromname . ,from-name))) (fromname . ,from-name)
,@(map
(lambda (file-details)
`(,(string->symbol
(string-append
"files[" (alist-ref 'filename file-details) "]"))
file: ,(alist-ref 'filepath file-details)
filename: ,(alist-ref 'filename file-details)
headers: ((content-type
,(alist-ref 'content-type file-details)))))
files)))
(abort "All parameters are required for successfully sending mail."))) (abort "All parameters are required for successfully sending mail.")))
) )

@ -11,5 +11,5 @@
; Files to install for your extension: ; Files to install for your extension:
'("send-grid.o" "send-grid.so" "send-grid.import.so") '("send-grid.o" "send-grid.so" "send-grid.import.so")
; Assoc list with properties for your extension: ; Assoc list with properties for your extension:
'((version 2) '((version 2.0.1)
(static "send-grid.o"))) ;; for static linking (static "send-grid.o"))) ;; for static linking
Loading…
Cancel
Save