Last active
August 24, 2016 20:14
-
-
Save ruslander/6482081 to your computer and use it in GitHub Desktop.
Update the api key to reflect your account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%curl -s --user 'api:key-8av0ox9abrs2icvagny' \ | |
% https://api.mailgun.net/v2/bang.mailgun.org/messages \ | |
% -F from='Excited User <[email protected]>' \ | |
% -F [email protected] \ | |
% -F subject='Hello' \ | |
% -F text='Testing some Mailgun awesomness!' | |
-module(mailgun). | |
-compile(export_all). | |
-define(ApiKey, "api:key-8av0ox9abrs2icvagny"). | |
start()-> | |
ok=application:start(inets), | |
ok=application:start(crypto), | |
ok=application:start(asn1), | |
ok=application:start(public_key), | |
ok=application:start(ssl). | |
go()-> | |
fire( | |
"Excited User <[email protected]>", | |
"[email protected]", | |
"Hello", | |
"Testing some Mailgun awesomness!"). | |
fire(From, To, Subject, Message)-> | |
Body = "from="++http_uri:encode(From)++ | |
"&to="++http_uri:encode(To)++ | |
"&subject="++http_uri:encode(Subject)++ | |
"&text="++http_uri:encode(Message), | |
io:format("~n Sending ~p ~n", [Body]), | |
Request = { | |
"https://api.mailgun.net/v2/bang.mailgun.org/messages", | |
[{ "Authorization", "Basic "++base64:encode_to_string(?ApiKey) }], | |
"application/x-www-form-urlencoded", | |
Body | |
}, | |
case httpc:request(post, Request, [], [{body_format, string}] ) of | |
{ok, {{_, 200, _}, _, Payload}} -> {ok, Payload}; | |
{ok, {{_, _, _}, _, Payload}} -> {error, Payload}; | |
Error -> Error | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment