An Erlang library for consuming the Postmark mail service API, inspired by the official Postmark PHP package https://github.com/wildbit/postmark-php.
- Build
- Quickstart
- Supported Operations
- Installation
- Data Types
- Record Types
- Modules Index
- Module Exports Details
- Simple Usage
$ rebar3 compile
To use erlang_postmarkapp from the console
, simply do this:
$ ./init.sh
This will build it and start the Erlang shell.
This library currently supports sending emails, handling bounces and managing servers. [are more functions in the planning?]
- Sending a single text or html email send_email/1, send_email/4, send_email/11
- Sending multiple emails in a batch: send_email_batch/1
- Sending a single email using a template: send_email_with_template/1, send_email_with_template/10
- Getting delivery stats: get_delivery_stats/0
- Querying for bounces: get_bounces/1
- Getting a single bounce: get_bounce/1
- Getting the dump for a bounce: get_bounce_dump/1
- Activating an email that had a bounce: activate_bounce/1
- Getting tags with bounces: get_bounce_tags/0
- Getting information about a server: get_server/0
- Editing a server: edit_server/1
Add it to your rebar.config
like so:
{deps, [
...
{erlang_postmarkapp, "1.*", {git, "https://github.com/emmanix2002/erlang_postmarkapp.git", {branch, "master"}}}
]}.
deliveryStat() = {inactive_mails, integer()} | {bounces, [#postmark_bounce_stats{}]}
deliveryStatsResponse() = [deliveryStat()] | {error, string()}
bounce() = #postmark_bounce{}
bounces() = [bounce()]
bouncesInfo() = {total, integer()} | {bounces, bounces()}
bouncesResponse() = [bouncesInfo()]
emailBody() = {text, string()} | {html, string()}
optionalValue() = string() | undefined
optionalListValue() = list() | undefined
postmarkEmail() = #postmark_email{}
postmarkEmails() = [postmarkEmail()]
sendEmailResponse() = {ok, string()} | {error, string()}
serverColor() = purple | blue | turqoise | green | red | yellow | grey
tag() = string()
tags() = [tag()]
trackLinkStatus() = none | html_and_text | html_only | text_only
-record(postmark_email, { from :: string(), to :: string(), subject :: string(), html :: optionalValue(), text :: optionalValue(), tag :: optionalValue(), track_opens=true :: boolean(), reply_to :: optionalValue(), cc :: optionalValue(), bcc :: optionalValue(), track_links :: trackLinkStatus(), template_id :: optionalValue(), template_model :: optionalListValue(), inline_css=true :: boolean() }) -record(postmark_send_response, { message_id :: string(), error_code :: integer(), message :: string() }) -record(postmark_bounce_request, { count=500 :: integer(), offset=0 :: integer(), bounce_type :: string(), email :: string(), inactive :: boolean(), tag :: string(), message_id :: string(), from_date :: string(), to_date :: string() }) -record(postmark_bounce_stats, { type :: optionalValue(), name :: string(), count :: integer() }) -record(postmark_bounce, { id :: integer(), type :: string(), type_code :: integer(), name :: string(), tag :: optionalValue(), message_id :: optionalValue(), server_id :: optionalValue(), description :: optionalValue(), details :: optionalValue(), email :: string(), from :: string(), bounced_at :: string(), dump_available :: boolean(), inactive :: boolean(), can_activate :: boolean(), subject :: string() }) -record(postmark_server, { id :: integer(), name :: string(), api_tokens=[] :: list(), server_link :: string(), color :: serverColor(), smtp_api_activated :: boolean(), raw_email_enabled :: boolean(), delivery_hook_url :: string(), inbound_address :: string(), inbound_hook_url :: string(), bounce_hook_url :: string(), include_bounce_content_in_hook :: boolean(), open_hook_url :: boolean(), post_first_open_only :: boolean(), track_opens :: boolean(), track_links :: trackLinkStatus(), inbound_domain :: string(), inbound_hash :: string(), inbound_spam_threshold :: integer() })setup/1,
setup/2,
send_email/1,
send_email/4,
send_email/11,
send_email_with_template/1,
send_email_with_template/10,
send_email_batch/1,
get_server_token/0,
get_account_token/0,
track_links_to_string/1
activate_bounce/1, get_delivery_stats/0, get_bounces/1, get_bounce/1, get_bounce_dump/1, get_bounce_tags/0,
activate_bounce(BounceId::integer()) -> {ok, bounce()} | {error, string()}
get_bounces(BounceRequestRecord::#postmark_bounce_request{}) -> bouncesResponse() | {error, string()}
get_bounce(BounceId::integer()) -> {ok, bounce()} | {error, string()}
get_bounce_dump(BounceId::integer()) -> {ok, string()} | {error, string()}
get_bounce_tags() -> {ok, tags()} | {error, string()}
get_delivery_stats() -> deliveryStatsResponse()
get_server() -> {ok, #postmark_server{}} | {error, string()}
edit_server(ServerRecord::#postmark_server{}) -> {ok, #postmark_server{}} | {error, string()}
setup(ServerToken::string()) -> ok
setup(ServerToken::string(), AccountToken::string()) -> ok
get_server_token() -> string()
get_account_token() -> string()
send_email(PostmarkEmail::#postmark_email{}) -> sendEmailResponse()
send_email(From::string(), To::string(), Subject::string(), Body::emailBody()) -> sendEmailResponse()
send_email(From::string(), To::string(), Subject::string(), HtmlBody::optionalValue(), TextBody::optionalValue(), Tag::string(), TrackOpens::boolean(), ReplyTo::optionalValue(), Cc::optionalValue(), Bcc::optionalValue(), TrackLinks::trackLinkStatus()) -> sendEmailResponse()
send_email_batch(PostmarkEmailList::postmarkEmails()) -> sendEmailResponse()
send_email_with_template(PostmarkEmail::#postmark_email{}) -> sendEmailResponse()
send_email_with_template(From::string(), To::string(), TemplateId::string(), TemplateModel::list(), Tag:: optionalValue(), TrackOpens::boolean(), ReplyTo::optionalValue(), Cc::optionalValue(), Bcc:: optionalValue(), TrackLinks::trackLinkStatus()) -> sendEmailResponse()
track_links_to_string(TrackLinkStatus::trackLinkStatus()) -> string()
Set up erlang_postmarkapp by providing the Server Token
[and optionally an Account Token
].
Before you start making calls, you must call the setup/1 or setup/2 functions to initialise
the library and start all required processes. We recommend putting the call to setup()
in your init
function, if you have any.
Here's a simple example of sending a plaintext email:
send_text_mail() ->
ServerToken = "your server token here",
erlang_postmarkapp:setup(ServerToken),
Body = {text, "Hello World!"},
case erlang_postmarkapp:send_email("signature@domain.com", "recipient@example.com", "A good example", Body) of
{ok, MessageId} -> io:format("Successfully sent email with MessageID ~p~n", [MessageId]);
{error, Reason} -> io:format("Message sending failed because ~p~n", [Reason])
end.
setup(ServerToken)
: sets the server token for authenticating with the Postmark API.send_email*()
: these functions allow you to send an email.
NOTE: based on the information on the Postman documentation, batch emails are limited to a maximum of
500 messages (the library enforces this). For single emails, you can have a maximum of 50 email
addresses from a combination of all To, Cc, and Bcc
addresses.