Initial version.

master
Thomas Hintz 11 years ago
commit a5b2ca3504

@ -0,0 +1,9 @@
(defpackage :cl-sendgrid-system (:use :asdf :cl))
(in-package :cl-sendgrid-system)
(defsystem :cl-sendgrid
:version "0.1"
:depends-on (drakma yason flexi-streams)
:components ((:file "packages")
(:file "cl-sendgrid" :depends-on ("packages"))))

@ -0,0 +1,20 @@
(in-package :cl-sendgrid)
(define-condition sendgrid-error (error)
((message :initarg :message :reader message)))
(defun send-email (&key api-user api-key subject to text html from)
(let ((r (parse (flexi-streams:octets-to-string
(http-request "https://sendgrid.com/api/mail.send.json"
:method :post
:parameters `(("api_user" . ,api-user)
("api_key" . ,api-key)
("subject" . ,subject)
("to" . ,to)
("text" . ,text)
("html" . ,html)
("from" . ,from))))
:object-as :alist)))
(if (string-equal (cdr (assoc "message" r :test #'string-equal)) "success")
t
(error 'sendgrid-error :message (cdr (assoc "errors" r :test #'string-equal))))))

@ -0,0 +1,5 @@
(in-package :cl-user)
(defpackage #:cl-sendgrid
(:use :cl :drakma :yason)
(:export #:send-email #:sendgrid-error))
Loading…
Cancel
Save