7 Email Attachment Tasks Small Businesses Can Automate With Python

The Wrong Attachment Usually Gets Automated First

Most small businesses that point Python at their inbox start with the wrong attachment. They automate whatever annoys them most, usually dragging invoices into folders, and the files that can actually hurt them are left to whoever opens them first. In most offices that order looks backwards. Because a script never gets tired, its value sits in the jobs where a tired person makes an expensive mistake, and the seven tasks below run from the costliest error to the cheapest. Minutes saved barely figure in the ranking.

Python is the easy part. It costs nothing, and a script of a few dozen lines can be read by whoever inherits it, which counts for more in a five-person office than anything on a paid tool’s feature list. The owner still has to decide which files a script may handle before anyone has looked at them.

1. A Holding Folder for Files Nobody Expected

The highest-stakes job decides which attachments reach a human at all. The UK government’s latest Cyber Security Breaches Survey puts phishing far ahead of every other kind of breach or attack, with 38% of businesses reporting it over the previous year.

At most small firms, a month of incoming mail follows a pattern dull enough to write down. The accountant sends PDFs. The main supplier adds a spreadsheet now and then, and hardly any regular sender would mail you a zipped folder and then type its password into the email body. A short script can check every attachment against that pattern, by file type and by sender, and move anything outside it to a holding folder before anyone double-clicks. That’s the whole trick.

Mail providers already scan for known malware, and the script replaces none of that. Filtering incoming mail by attachment type is a standard layer of phishing defense, and even the advice that recommends it admits some attacks will get through anyway. Your provider has no way of knowing that your suppliers never send zip files. Your script does, because someone in the office wrote that rule after watching the same twenty senders for years.

For the first two weeks, the script is best run in watch-only mode, logging what it would have held without moving anything. Ninety days of old mail usually shows which file types each regular sender really uses. A few file types can skip the watching period and go to the holding folder from the first morning. Any Office file that asks permission to run macros qualifies, as does a zip file locked with a password nobody mentioned. A web page sent as an attachment is stranger still, and few genuine suppliers ever send one.

2. Paperwork From a Driver’s Phone

Plenty of attachments arrive as pictures rather than documents. A delivery note photographed on a driver’s phone looks like a document to whoever opens it, yet to a script it holds no words at all. Until character recognition turns the picture into text, no later step can search it or pull a total from it. This is also where a script’s mistakes get expensive in a new way. A misread digit doesn’t announce itself. It sits in a spreadsheet cell looking exactly as confident as the correct figures around it, and nobody checks it until a customer disputes the bill.

The Python OCR library that Apryse sells as an add-on to its server toolkit has a tutorial that takes about four minutes to read. Raising the resolution to 300 dots per inch is one adjustment it says can improve results, and areas of a page that don’t matter can be left out of the reading altogether. The tutorial stops short of naming one best engine and suggests trying several against your own documents and adjusting resolution and scan settings until the output holds up. Then comes a warning that reads like boilerplate. License keys are never to be published, it says, not even in a public GitHub repository. Small businesses would do well to read that line twice. Their scripts tend to be written by freelancers, many of whom keep their code public out of habit, partly as a portfolio.

Leaked keys are common enough to be counted. Public GitHub commits picked up 28.65 million new hardcoded secrets in 2025, a 34% jump on the year before. A license key belongs in a password manager or in the server’s environment settings, and the script can read it from there.

Misreadings are easier to catch while the photo is still one click away. If every extracted row carries a link back to its original image, whoever checks a doubtful figure can compare it with the photo in seconds. The script also adds up the line items, compares the result with the stated total and flags any delivery note where the two disagree.

3. Outgoing Mail, Where a Script Can Do More Damage

On outgoing mail, automation can make things worse. A bookkeeper who attaches the wrong statement to an email exposes one customer’s balance to one stranger, which is bad enough. A script with the same fault repeats it for the whole mailing list in seconds. Payslips are the worst case, since a wrong attachment there tells one employee exactly what a colleague earns. Why automate it at all?

By hand, the job gets done at month end by whoever drew the short straw, and people make mistakes under those conditions. Figures from Australia’s privacy regulator attribute 37% of the data breaches notified in the first half of 2025 to human error, and the manual version looks far from safe.

Python’s own documentation includes an example script that emails every file in a folder to a list of recipients. Nothing in it checks whether a file belongs to the person receiving it. That check is the job. If every statement carries the customer’s account number in its file name, a script can compare it with the number stored against the email address and refuse to send whenever the two disagree. Refusals are cheap. An apology to the whole mailing list is not.

Before the first real send, a dry run costs nothing. The script writes every message to a folder instead of sending it, someone opens a handful at random, and only then does a live batch go out, ideally to an internal address first. A log of the recipient and file name for every message sent turns a customer’s complaint into a five-minute lookup.

4. Let the Address Do the Sorting

The cheapest way to sort incoming attachments is probably to let the address do it. A script that reads subject lines to decide whether an attachment is an invoice or a job application is likely to be wrong often enough to create more work than it saves. Subject lines are written by people in a hurry. Plenty consist of nothing but a forwarded reply to a forwarded reply, and every so often an invoice turns up titled “quick question.”

Separate addresses for separate jobs settle the question before any code runs.

Anyone can create several addresses that all land in one inbox without paying for a second account, so suppliers can be asked to send bills to one while applicants write to another. The script then reads the address a message was sent to, which is a fact, instead of its subject line, which is a mood. Guessing from content can come later, if ever.

The changeover is rarely clean. A polite automatic reply can point stragglers to the new address, and anything still landing in the main inbox goes to a person rather than the script.

5. File Names That Still Make Sense Years Later

Filing sits fifth here, though it’s the job most owners automate first. A file called scan0042 in a downloads folder still exists, but nobody will find it when the accountant asks. Every office also has a document somewhere called final_v2_FINAL, and it’s never the last version. A script can rename each attachment by date and sender the moment it arrives, then drop it into a folder for that month. Year-first dates keep each folder in order. If the accountant wants October’s invoice from Harbor Supplies, a file named 2026-10-17_harbor-supplies_invoice can be spotted in the folder list without opening anything.

The tax rules decide how long those folders need to survive. In the United States, business tax records generally have to be kept for three years, with longer periods for some claims and at least four years for employment tax records. A naming scheme that seemed obvious in March has to make sense to an accountant years later, possibly after the person who invented it has left.

Other countries run longer clocks. Canada’s revenue agency expects records to be kept for six years from the end of the last tax year they relate to, so a filing script that deletes on its own schedule is a liability. Originals are best stored read-only, with the renamed copies beside them, so a bad rename can always be undone.

6. The Same Invoice, Twice

The same invoice tends to arrive twice, once from the supplier and once forwarded by a colleague who assumed nobody had seen it. Paying it twice is the obvious risk, and a script that takes a fingerprint of each file’s contents can flag the second copy even when its name has changed.

Fingerprints have a blind spot. A supplier who exports the same invoice a second time usually produces a file with different bytes, so the script does well to compare the invoice number and the amount once the text has been read.

Storage is the less obvious risk. Reply chains drag the same twelve-page contract along with every answer. Gmail, Drive and Photos draw on the same allowance of up to 15GB in a standard Google account, and attachments sitting in old messages count against it. That’s worth knowing before anyone compares free cloud storage plans to hold an archive that is mostly copies. Sharing a link to one stored file, instead of attaching it again, removes most of the waste at the source, though few small offices have the habit.

7. A Morning Report With a Pulse

Reporting decides whether the other six tasks can be trusted. By eight each morning, the owner gets a short email listing what the script filed overnight and what it held back. Files it couldn’t read belong on that list too. Without them, the email describes a script that never seems to fail, and few scripts work that well.

Held files need a person to look at them, and for that a small review page beats another email. Python libraries such as Gradio and Streamlit can turn a script’s daily output into a page with buttons, so a held attachment can be released or deleted in one click. That page is where the doubtful readings from the photographed delivery notes belong as well. Nobody enjoys checking them.

Without a way to notice its absence, a daily report protects nobody. Monitoring services work as a dead man’s switch, staying silent while a job checks in on schedule and raising an alert when it misses one. A script that pings such a service after every run turns its own silence into an alert, delivered through whatever channel the owner actually watches.

Who Ends Up Owning the Script

Python makes the hiring easy. In Stack Overflow’s 2025 developer survey, 57.9% of respondents reported extensive work in the language over the past year, up seven points, so a freelancer who can read the script is rarely hard to find.

Nobody can hire the history behind each rule, though. Offices once kept that history in a receptionist’s head, including which faxes went straight in the trash, and it left the building at the retirement lunch. Writing it down takes an afternoon. A single page next to the script will do, with one line per rule saying what the rule is for and who asked for it. Moving the code into a private repository and giving a second person access is another afternoon’s work.

The Case for Building in Reverse

None of this means the list should be built from the top. The ranking measures damage, and damage is exactly what nobody should be practicing on. A misbehaving filing script costs an afternoon. A quarantine rule written before anyone has watched it fail will, sooner or later, hold back the one invoice that mattered most. In practice most scripts break early, usually on a file nobody thought to test, and the cheapest place to find that out is a folder of receipts. So the order of importance and the order of construction run in opposite directions, and a business has to keep both in mind at once.

When the Inbox Goes Quiet

Before anyone writes a line of code, pull the last ninety days of attachments and list the file types each regular sender actually uses. That list is rule one for the holding folder, and the filing script can be tested against the same files. Then put two names next to the script, an owner and a deputy.

The harder problem comes later, once everything works. After a few months of identical morning summaries nobody reads them, and a script that died in March can look exactly like one having a quiet spring. A heartbeat alert helps, right up to the point where it goes to the person who wrote the script and has since moved on.

Every safeguard on this list ends in a message to a person, which is an awkward dependency for a project whose whole purpose was to need fewer of them.