You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
(in-package :cl-sendgrid)
|
|
|
|
|
|
|
|
(define-condition sendgrid-error (error)
|
|
|
|
((sendgrid-error-message :initarg :sendgrid-error-message :reader sendgrid-error-message)))
|
|
|
|
|
|
|
|
(defun send-email (&key api-user api-key subject to text html from reply-to)
|
|
|
|
(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)
|
|
|
|
("replyto" . ,reply-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 :sendgrid-error-message
|
|
|
|
(cdr (assoc "errors" r :test #'string-equal))))))
|