Using Mailgun with Electric Imp
January 7, 2014
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ย mailgun.com 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.
Agent
function mailgun(subject, message) { local from = "[email protected]"; local to = "[email protected]" local apikey = "key-something--something"; local domain = "sandbox34252.mailgun.org"; local request = http.post("https://api:" + apikey + "@api.mailgun.net/v2/" + 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.
11 Comments
Thank you!
Found any use for this? ๐
thanks! this turns out to be the easiest way (with mailgun) to get notification for a small, personal, one-off thing (alerting me to water my plants based on moisture sensor output)
Have you seen this one too? http://captain-slow.dk/2014/01/03/using-pushover-with-electric-imp/
I prefer that over mail for just small alerts.
thank you!
I keep getting the fallowing error when using it.
ERROR: the index ‘http’ does not exist
Any idea what I did wrong?
I have no idea, I just tested it again by just copy/pasting the code, and put my api key and such in. Worked fine, are you putting it into the Agent code?
I keep getting the fallowing error when using it.
ERROR: the index ‘http’ does not exist
Any idea what I did wrong?
I have no idea, I just tested it again by just copy/pasting the code, and put my api key and such in. Worked fine, are you putting it into the Agent code?
Hello,
I need help with this ….I have the mailgun connection and all but i still cant get email
Kindly help
Or is there a reference i should put on the agent code?