Using Mailgun with Electric Imp

Another example in my “Using something with Electric Imp” series. ๐Ÿ™‚

This time it is time for sending good old E-Mails.

The Electric Imp system does not include any way to send mails, but this isn’t a big problem. Over atย they provide a free (up to 10.000 mails per month).

All you need to do is to register a user on their site, find your api key and domain that got assigned to you, and put them into the function posted below.


function mailgun(subject, message)
  local from = "";
  local to   = ""

  local apikey = "key-something--something";
  local domain = "";

  local request ="https://api:" + apikey + "" + domain + "/messages", {"Content-Type": "application/x-www-form-urlencoded"}, "from=" + from + "&to=" + to + "&subject=" + subject + "&text=" + message);

  local response = request.sendsync();
  server.log("Mailgun response: " + response.body);
mailgun("Electric Imp", "Just saying hi! :)");

This should give a response looking something like this

2014-01-07 21:59:52 UTC+1: [Agent] Mailgun response: { "message": "Queued. Thank you.", "id": "<>" }

And in your mailbox you should have a mail with the subject “Electric Imp” and the test saying “Just saying hi! :)” in it.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.