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 = "[email protected]";
  local to   = "[email protected]"

  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": "<[email protected]>" }

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



Add a Comment

Your email address will not be published. Required fields are marked *