This worked fine, WWW::Mechanize, LWP::UserAgent, and JSON to handle the messages from the API. You will have to put in your own valid ids etc. The ones below are randomized/edited.
use strictures;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->credentials( api => "key-da0f99505ece11e48064d6516832a126" );
$mech->post( "https://api.mailgun.net/v2/xyz.mailgun.org/messages",
[ from => 'Mailgun Sandbox <postmaster@sandboxyz.mailgun.
+org>',
to => 'Kitty <fluffy@cats.co.uk.jp.org>',
subject => 'OHAI',
text => 'Congratulations! You are a winner. A loser no
+more!!' ]);
print $mech->response->as_string, $/;
{
"message": "Queued. Thank you.",
"id": "<20141028181741.33218.21053@sandboxyz.mailgun.org>"
}
First principles, I really recommend against cut and paste
programming. You have to know what everything does or you might do
something dangerous and you will certainly waste time treating each
script as a mystical invocation.
I also think you should have included the real service and such in your original question to make it easier. Not that it was hard to find but if you want help, lowering the bar to do so is often the difference between an answer in 30 minutes and an answer never.