Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/camdez/sendgrid
A Clojure library for sending emails with SendGrid.
https://github.com/camdez/sendgrid
Last synced: 2 months ago
JSON representation
A Clojure library for sending emails with SendGrid.
- Host: GitHub
- URL: https://github.com/camdez/sendgrid
- Owner: camdez
- License: mit
- Created: 2016-02-07T07:18:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-19T21:45:03.000Z (about 2 years ago)
- Last Synced: 2024-10-28T13:07:03.638Z (3 months ago)
- Language: Clojure
- Size: 25.4 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sendgrid
[![Clojars Project][clojars-badge]][clojars-sendgrid]
A Clojure library for sending emails with [SendGrid][].
## Usage
```clj
(require '[sendgrid.core :as sendgrid])(def sg-config
{:api-key "d34db33f"});; Send a plain-text email
(sendgrid/send-email sg-config
{:to "[email protected]"
:from "[email protected]"
:subject "SendGrid Test"
:text "Email body here."})
;; => {:message "success"};; Send an HTML email
(sendgrid/send-email sg-config
{:to "[email protected]"
:from "[email protected]"
:subject "SendGrid Test"
:html "Email body here.
"})
;; => {:message "success"}
```For details on individual request params, please see the
[SendGrid API documentation][sendgrid-api-docs].Emails can also include attachments via the `:attachments` param.
Attachments must be a sequence of maps where each map contains a
`:name` and `:content` and optionally a `:mime-type` (`String`).
`:content` can be a `File`, `InputStream`, `ByteArray`, or `String`.```clj
(let [attachments
[{:name "plain.txt", :mime-type "text/plain", :content "Simple."}
{:name "yay.jpg", :content (-> "yay.jpg" io/resource io/file)}]]
(sendgrid/send-email sg-config
{:to "[email protected]"
:from "[email protected]"
:subject "SendGrid Test"
:html "Email body here.
"
:attachments attachments}))
;; => {:message "success"}
```## Testing
To run the tests you'll need the following environment variables set:
- `SENDGRID_API_KEY`
- `FROM_EMAIL`
- `TO_EMAIL`Alternately you can set these values in a `profiles.clj` file (see
[Environ][] for more information).Please note that the tests will send real emails to the `TO_EMAIL`
you've set, and will count against your SendGrid email quota.## Motivation
Features differentiating this library from (some of) the alternatives:
- Idiomatic Clojure.
- No global state.
- Convenient handling of files (whether generated or served from
the file system).
- No errors on long message contents.
- No assumptions about error handling (error handling is caller's
responsibility).## License
Copyright © 2016 Cameron Desautels
Distributed under the MIT License.
[clojars-badge]: http://clojars.org/camdez/sendgrid/latest-version.svg
[clojars-sendgrid]: http://clojars.org/camdez/sendgrid
[sendgrid]: https://sendgrid.com
[environ]: https://github.com/weavejester/environ
[sendgrid-api-docs]: https://sendgrid.com/docs/API_Reference/Web_API/index.html