After 15 years, I have finally reached the point where I use Outlook as my build pipeline
Posted by codingtofreedom@reddit | programming | View on Reddit | 65 comments
I had an annoying problem at work where we had to work around some less-than-optimal firewall rules, and because we are working on a tool that requires quite frequent testing (like several times per hour we work on it), it was really adding up to take these five-minutes per file that it took to get them from my coworker's machine to mine, and I quickly designed a server workflow that could take the encoded file and save it to its own file system.
Because we could not find a good way to bring these files over, we figured it was actually a good idea to send it via email to an inbox with a specific subject line, and then have a Python script on my end checking the inbox every minute to then take the attached file and send it to the endpoint.
This has to be one of the hackiest solutions I have come up with over the years for a problem that wouldn't have to be one if my coworker was simply allowed to call the endpoint from his code, but I found it interesting how simple it actually is to connect from a Python script to a local Outlook client and parse the results. Less than 100 lines of code, and we have a "build pipeline" going that reduces our manual overhead significantly.
TadpoleNo1549@reddit
this is such a classic “it shouldn’t work but it does” solution, honestly love how you just worked around the system instead of fighting it, turning email into a mini pipeline is peak developer creativity, sometimes the hacky solutions are the ones that actually save the most time
TadpoleNo1549@reddit
this is such a classic “it shouldn’t work but it does” solution 😭 honestly love how you just worked around the system instead of fighting it, turning email into a mini pipeline is peak developer creativity, sometimes the hacky solutions are the ones that actually save the most time
Spiritual_Cycle_7881@reddit
Outlook was a part of the data pipeline in my ETL config 😆 An org had an app adopted and the app required additional fee to enable API and export feature. No money, dear! Invent something. Direct db access forbidden (security!)
Okay, the app allows you to generate xlsx reports and email them on a schedule. Data volume is tiny (10k rows, 5M) - why not? I created a service account and used python requests to scan inbox via MS Graph API (no client libs because it was 20 sloc in pure requests). Worked like a charm, saved some subscription money.
The most difficult part was setting up the auth process properly: removing 2FA for the service acc and limiting senders list using allow/block lists or something. Spent a day or two on this part.
UnderstandingFun2119@reddit
If you’re going to keep Outlook-as-pipeline, treat the mailbox like a queue with strict auth, filtering, and idempotency.
What’s worked for me: use Graph application permissions with a cert (app-only) so you don’t have to weaken 2FA on a user; subscribe to /messages/delta so you only process new stuff. Whitelist sender addresses and attachment MIME types, hard-cap size, and reject anything else to a Quarantine folder. Dedupe with internetMessageId + a hash of the attachment and store a tiny state table (sqlite/Redis) so replays don’t double-run. Move processed mail to a Processed folder and send failures to a Poison folder after N retries. If you can add a cloud step, have Power Automate drop attachments to Blob/SharePoint, then an Azure Function validates and forwards to your endpoint. I’ve also used Postman to mock this flow, and when we needed downstream tools to read the results, DreamFactory exposed a read-only REST API from SQL Server without extra glue.
Net: mailbox as a queue, app-only auth, delta queries, idempotency, and strict allowlists.
Spiritual_Cycle_7881@reddit
Yep, probably a cert or something instead of push notifications, I cannot recall tbh. Other things were much easier, I didn't bother with all these things: request emails filtered by the subject line for the last 24 hours, must be signed verified (I guess some cert as well), push attachments into DWH LZ. Done. Let the downstream pipeline to sort the things out - it was a tiny SCD type 1 as a destination.
It was a "temporary solution until finance sorts things out how to budget the API subscription" haha, worked like this for a year or so until moved to another data provider
codingtofreedom@reddit (OP)
That sounds fun! 😀 I am often appalled when I hear how much some features can cost in industrial software, especially when they make you pay for each iteration instead of a flat fee.
brunogadaleta@reddit
Since the days I used Ftpmail to download Linux ISO, I realized that no-so-modern mail protocols are like every other protocols.
Which lib do you use? Can you share the code?
codingtofreedom@reddit (OP)
Directly via pywin32. Not sure how well the code copies over here, but the interesting bits were this how to connect to your inbox:
And then this here to filter for the newest unread message that fits the subject line in the right folder:
And then finally this is how to access the attachments of that email:
xylarr@reddit
Weird. Folder number six is the inbox.
codingtofreedom@reddit (OP)
Yeah, I was confused by that as well so I looked the numbers up. I forgot already, but the other IDs were things like sent email, trash bin or outgoing-but-not-sent-yet.
larsga@reddit
Why use Outlook instead of connecting to the mailbox directly over IMAP/POP3?
em__jr@reddit
If the OP's backend mail server is Exchange, it may not have been configured for IMAP/POP3.
Outlook's COM Object model, which the OP accessed through pywin32, is a relatively thorough API. It was designed for purposes like this Python script.
It's certainly an interesting workflow, no doubt!
decimalturn@reddit
You were this 🤏 close to becoming a VBA dev
codingtofreedom@reddit (OP)
Haha, all office products have scripting blocked to prevent smart people from doing dumb things 😀
decimalturn@reddit
Really? So you can run a Python script, but not VBA?
codingtofreedom@reddit (OP)
Yes, because I have a developer machine that is more open than most, but Outlook/Office are handled company-wide. Even so, I have no local admin rights and need to ask for many things to be installed, or run them in a virtual machine (that I had to ask to have set up for me). It's the way things go in many companies these days. For developers, it can get a bit annoying at times, but honestly it doesn't get in the way much, and I can see why they would rather not have most people as local admins or downloading scripts that then infect the whole company with ransomware 😀
enderfx@reddit
We used to download anime episodes that were hidden in 60/70+ JPEG files, each of them around 1MB in web. Then a program (something like chameleon?) would take the video stream and put it back together as an AVI file. The JPEGs themselves would still render an image / be valid
This was at the beginning of the Megaupload/VK times IIRC, and things like JDownloader did not exist yet (torrent even less, it was ed2k/emule times).
Usually the JPEG would be hosted on Lycos, Geocities and the likes. And usually a couple of mirrors, since a missing JPEG would invalidate the rest.
codingtofreedom@reddit (OP)
Wow I love that story, never heard of that process before. The earliest I remember is trying to find someone who had pack69 of a 80 packs upload on PirateBay when we were kids 😀
crummy@reddit
this is so cursed
Sorry-Transition-908@reddit
I love it but I hope that firewall gets more sane in the future
codingtofreedom@reddit (OP)
Hopefully soon, yes 🙂
Worth_Trust_3825@reddit
/r/programmingcirclejerk ass post
Successful-Money4995@reddit
You'd think that by now we'd have invented a way to copy a large file from one computer to another. Yet we literally haven't.
codingtofreedom@reddit (OP)
True, just like it took forever to get a reliable way to copy images from the phone to the computer (at least that works great now)
SadInstance9172@reddit
This is the way. Ive used free gmail accounts instead of a "proper" message broker before. Works really well
codingtofreedom@reddit (OP)
Now that I think about it, that's how a lot of the low-code automations I've seen get triggered 🤔
All_Work_All_Play@reddit
Someone once told me "The two systems don't need to be connected through an API, they just need to look like they're connected through an API".
And that's how the MVP for a credit monitoring service of a half billion dollar shipping company ended up using email to look like the two different systems were talking to each other.
amakai@reddit
True. And if the mail is also not available, you can always fallback to IPoAC.
cat_in_the_wall@reddit
I've done this exact same thing. At an old job we had a massive system and the builds were looong and better: flaky. I couldn't access my work machine outside the office, but I could do email. So when stuff failed, I could email myself a specific message and I had an outlook plugin that would take action.
i suddenly became one of the most productive people on my team simply because i wasn't waiting for builds as often. these days i wouldn't try that hard, but as a new junior i was eager to please.
slyiscoming@reddit
This is so terrible it's amusing. There must be at least a hundred better solutions to share those files.
That said, all of the Microsoft Office apps have extensive APIs. Years ago I wrote an app that dynamically created PowerPoint presentations and the API made it very easy
hennell@reddit
This is complete madness, an awful insane solution and I understand entirely.
The one thing with hacks like this is that if it is working around a problem that problem is now fixed and will never get solved. If the underlying issue of permissions is something that should be fixed, automate nagging for the real solution too. When you send a message to the end point also send a message to whoever is ment to give permissions to note that "you" just had to manually upload a patch because permissions aren't fixed yet. Randomise the subject to so it's harder for them to ignore then they/you won't forget about the issue and this hack won't be around forever...
goomyman@reddit
I keep saying this. Outlook should have a database option.
Email as database. Your personal email.
That’s how people use it all the time.
Something like send an email - with a specific custom title or some tag. And it gets stored differently than email in some type of indexed database.
This would reduce 95% of work email IMO.
Nobody wants an email for every update of an incident. They just find email more convenient to read and filter and search. You know database functionality.
Outlook for should “email as data” that’s done just directly as an email. But not just filtered, indexed and stored differently than email - treated as data for personal use.
And it should be automatic for public use - right now every person is encouraged to send emails to everyone and it’s up to the user to filter it into the void never to be seen again. Instead - email as database can be stored centralized with runtime load that looks like an email. User wouldn’t know it’s not just an email.
This could save massive amounts of spam. 99% of work emails are this garbage- incase the 1% might want to search something sometime.
flanger001@reddit
If it seems stupid, but it works, it isn't stupid.
i_dont_know@reddit
Curious if this is the “new” or “classic” outlook clients? Windows or macOS? Are these python bindings that Microsoft released?
codingtofreedom@reddit (OP)
It's the Classic outlook hosted on prem as a desktop client, from what I can tell the new version is no longer a desktop client and doesn't expose COM interface? On Windows using pretty standard connectors, but now that you mention it that might not work with current gen outlook the same way. I took a quick dive and it seems that new Outlook has to be set up with OAuth access and stuff, I guess that would turn the quick hack into taking more time than its worth.
arpan3t@reddit
Assuming you’re using M365 since you’re using Outlook as your mail client; you should look at Graph change notifications. You can subscribe to change events on various M365 resources like when a message is received by a mailbox.
The benefit being that you don’t need to have your workstation running with Outlook like your solution.
I used it to set up a solution for our IT ops that takes a .heic image attachment from a received email —> converts it to .png —> replies with the .png attached.
They get a bunch of emails asking to “open” the .heic attachment from users that get emailed images taken from iOS devices, because Windows doesn’t natively support the format.
beyphy@reddit
If Microsoft Graph isn't an option for whatever reason, you could also look into Logic Apps or Power Automate. I think both are just a GUI layer over Microsoft Graph.
arpan3t@reddit
Good option too! One thing to note is that the trigger for when new email arrives is limited to 50Mb total email size.
If Exchange admin has increased the max send/receive size for your mailbox, and the file being sent is > 50Mb, then Power Automate and Logic Apps won’t work.
PerceptionDistinct53@reddit
Jokes on you, now op will have to go through the bureaucracy mess to access his own outlook via Graph API.
arpan3t@reddit
lol well there is that!
Fr though, unless admins blocked it, they should have permissions to their own resources.
I would be so embarrassed if I found out one of our devs had to build OPs solution just because network admin wouldn’t/couldn’t setup a route.
codingtofreedom@reddit (OP)
Yes it's a bit of bureaucracy getting in the way, I hope it comes off as tongue in cheek because I expect the access to be given any day now, it just takes long and we are already developing on the tool so it just overlaps. We are hierarchically part of different teams so the approval has to go through an actual process which just takes time.
arpan3t@reddit
As long as the reasoning is sound, I’m all for policies and procedures! Good on you for making it work with what you have available to you!
monty_mcmont@reddit
HERESY! I admire your creativity though 🥴
Dizzy-Revolution-300@reddit
Why is the contrast so awful? Light gray on white background
codingtofreedom@reddit (OP)
Really? I am using a dark mode plugin for all sites anyway (highly recommend: dark reader), but I just disabled it and it looks fine to me, white on dark background 🤔
Dizzy-Revolution-300@reddit
https://i.imgur.com/aYebiVJ.png this is how it looks for my on firefox mobile
codingtofreedom@reddit (OP)
The fix was simple, I just had to force the desktop theme on mobile. I just checked on my phone and it seems to look good, thanks again for letting me know.
Dizzy-Revolution-300@reddit
Works for me now! I think some padding + font-size could be adjusted, but it's readable now, thanks!
codingtofreedom@reddit (OP)
Thanks for reporting, I'll investigate. I haven't actually tested the theme on mobile, I'll see if I can fix that.
ScriptingInJava@reddit
Interesting post, title would be a very fitting one for /r/programmingcirclejerk
Another post of yours caught my attention, had a read through and was hoping you'd be willing to share the updated version of the script linked at the top? Couldn't see a version of it available beyond the initial one in the thread on the AHK forum, would be super handy. Thanks!
codingtofreedom@reddit (OP)
Thank you! Here, see if this works for you, sorry but I threw out all my corrections, lots of personal stuff in there but it should work and allow you to add your own: https://pastecode.io/s/oah5q334
If you manage to get it working, can you get back to me? Then I'll add it to the post for everyone, I just realized that I forgot I wanted to do that.
ScriptingInJava@reddit
Wow yep, just outright worked. Did need to install v1.37.XXX (marked as deprecated on the AHK site) but ran the script and boom, instantly available. Really appreciate it, thanks.
codingtofreedom@reddit (OP)
Perfect, thanks for testing! I'll add the script to the post.
ScriptingInJava@reddit
Makes sense, thank you! I'll give it a spin now, if I make any changes I'll keep track of them so you have a "whitelabeled" one for your post.
FoeHammer99099@reddit
It taking weeks for someone's firewall privileges to get applied is the kind of problem you can throw managers at. If my skip learned that we we had to hack together our own solution after weeks of a manual process, heads would roll.
Redtitwhore@reddit
I remember way back when you could write vbscript directly in the email client. I would send myself emails with commands, they would get run on my computer and email me back the results.
codingtofreedom@reddit (OP)
You know, that's what I actually researched the other day to auto-generate JIRA tasks, that was one of the first projects I did as a junior dev, I think it was Excel VBA that called an endpoint using some deprecated method. Sadly, our access to those is locked down via company rule 😕 I have good memories of that setup, even though vbscript is paiiiiiinful to write 😀
SpringDifferent9867@reddit
Did something similar many years ago to be able to run code on remote stations. UUCP is often thought of as just the predecessor to SMTP but it was a full unix to unix copy and execution protocol.
elsatan666@reddit
This is really interesting, I hadn’t heard of UUCP before, thanks!
codingtofreedom@reddit (OP)
That sounds fun
SpringDifferent9867@reddit
Fun or challenging? 🙂
We did not have live internet from end to end at the time. Often routers used dial-up a few times a day, some even shutdown after each work day and during weekends, so “telnet” was not an option.
We could have used long distance calls (to great expense) but instead we used UUCP to issue a command and then maybe a week later the message would have travelled through the entire route and the first remote stations would start to do something.
yotemato@reddit
Fascinating. Did this cause any increased packet loss?
SpringDifferent9867@reddit
UUCP is (like SMTP) a store-and-forward protocol. If the message doesn’t end in its complete form at the end of the route, it will time-out and the error will start its merry way back.
So any packet loss would be invisible to us but we would know if something bad happened. if that is what you asked? 🙂
samfynx@reddit
Usenet reinvented.
walmartbonerpills@reddit
I've seen Jenkins used for managing batches. I love seeing how non devs use dev tools.