cr-postmark
Crystal Postmark
This shard provides an API client for the (Postmark Email API)[https://postmarkapp.com/developer] so that you can send emails from crystal.
Right now this shard only supports:
- Sending email
- Sending templated email
- Sending batched email
- Sending batched templated email
There are currently no plans to expand to the rest of the Postmark API, but Pull Requests would be reviewed and accepted if they provided the functionality :)
Installation
-
Add the dependency to your
shard.yml
:dependencies: cr-postmark: github: vici37/cr-postmark
-
Run
shards install
Usage
require "cr-postmark"
# Initialize the client with your server token
client = Postmark::ServerClient.new("SERVER_TOKEN")
# And begin sending email immediately
resp = client.deliver_email(
to: "destination@email.com",
from: "myself@of.course",
subject: "Hello World!"
text_body: "Hello!"
)
resp.error_code # => 0
resp.message # => "OK"
# Can send templated email too
client.deliver_template(
to: "destination@email.com",
from: "myself@of.course",
template_alias: "welcome-email",
# The template model can be a Hash(String, String),
# or any JSON::Serializable object for custom models
template_model: {"name" => "Art Vandelay"}
)
# Sending batches is easy
client.deliver_batch([
client.email_of(to: "destination_1@email.com", from: "myself@of.course", subject: "Email 1", html_body: "<span>Hello World!</span>"),
client.email_of(to: "destination_2@email.com", from: "myself@of.course", subject: "Email 2", text_body: "Hello World!", message_stream: "other-outbound")
])
# Including batched templates with custom models
class MyModel
include JSON::Serializable
getter name : String
def initialize(@name : String); end
end
client.deliver_template([
client.template_of(to: "another@destination.email", from: "myself@of.course", template_id: "1234", template_model: MyModel.new("Art Vandelay"))
])
Contributing
- Fork it (https://github.com/vici37/cr-postmark/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Troy Sornson - creator and maintainer
Repository
cr-postmark
Owner
Statistic
- 0
- 0
- 0
- 0
- 3
- over 2 years ago
- April 12, 2022
License
MIT License
Links
Synced at
Sat, 21 Dec 2024 12:52:56 GMT
Languages