4 ms·
I was expecting this to use a genuine mail server on the target device, because that actually wouldn’t be very difficult—configuring a mailbox to deliver messag
by chrismorgan 9y ago
I was expecting this to use a genuine mail server on the target device, because that actually wouldn’t be very difficult—configuring a mailbox to deliver messages to a program is standard fare for a mail server. For that matter, you could write the entire thing in a Sieve script (filter messages containing “open sesame”, and then execute such-and-such a program, so long as your server includes some way of executing a program in a Sieve script, such as Dovecot’s vnd.dovecot.execute extension).
Still, since we’re going with the “do everything over the web!” route—
With JMAP, you’ll be able to use plain old HTTP Event Source to listen for emails if you want (http://jmap.io/spec-core.html#push http://jmap.io/spec-core.html#push) without the need for a third-party service, though that will just tell you “there’s a new message” and you’ll have to fetch it through a normal JMAP request (getMessages, that would be).
This will still probably be out of scope for pure shell scripting, but it won’t require much code, just a decent HTTP library. I haven’t really thought about it—maybe you could string something together with cURL and a bit of piping.
(I work for FastMail and we’re sponsoring JMAP development. It’s coming along nicely, and I believe we plan to take our JMAP implementation live fairly soon. I’m sure we’d love to hear about people making toys like this with it!)
- andrewchambers 9y agoMy API is quite simple, you connect to api.websocket.email/v1/subscribe with a websocket an an HTTP header. It just saves a bit of time when you don't want to read specs like that, maintain a server, or setup credentials. At some point it makes sense to setup your own servers though. It's up to the individual to decide. I just wanted a way to write some unit tests, had to setup an email server, then made my test interface public.
- vog 9y ago> configuring a mailbox to deliver messages to a program is standard fare for a mail server Why?! Why would you run a separate mail server of that device? All you need is IMAP (or POP3), to connect the device to an existing mail server.
- chrismorgan 9y agoYou could do it that way, but (a) it’s much more satisfying to have it run the mail server itself, and (b) it’ll be markedly faster because the message is going to the server rather than to a third-party server, which will then notify your device. POP3 is a polling protocol, so you can’t realistically use it for anything real-time. For IMAP, your server probably supports IDLE, and you’ll need to use a client that supports IDLE as well. I’m not familiar with what’s available in IMAP client libraries; people put most of their email client effort into user agents. Everything IoT should run its own mail server, just for the fun of it. Bonus marks if it causes an RCE vulnerability. (But I’d say you’re pretty safe from that with Dovecot.) But seriously, email servers aren’t actually that scary. I wish more people ran their own, and more developers could comfortably work with them. Especially as an endpoint for something like this, running your own email server is perfectly feasible and reasonable—it’ll only accept messages to one mailbox, which will be immediately processed and discarded, so there’s no storage. It’s simply a C&C module.
- andrewchambers 9y agoWould need some way to get through NAT, at least here. Maybe ngrok will work with smtp too. I find the thought using email for IOT pub sub hilarious no matter how you do it.
- vog 9y ago> Would need some way to get through NAT, at least here. And you need to setup DynDNS or similar. Having a persistent IMAP connection sounds much less troublesome to me.