Turning enquiry emails into quote drafts
A self-hosted Python tool: how it reads mail, how it prices an order, and the parts a person still has to confirm.
Email quote automation is a self-hosted Python tool. It takes unread enquiry emails from a mailbox, translates them into the target language when needed (Chinese by default), works out a price from your quoting rules, and drafts a reply you can send as-is. Every step leaves a file on disk.
This is how it is put together, what each part relies on, and the parts a person still has to confirm.
Why I built it
Enquiry emails arrive in every shape. Some state the quantity and size; others just ask for a price. The quoting rules don’t change: material, size, process and quantity discount all follow a formula. Working through those rules by hand, looking up the price, then writing the same reply again for every email is repetitive, and it is easy to miss something.
I wanted the rules in code, with the machine drafting the quote and a person confirming it before it goes out.
The route an email takes
- Log in over IMAP and take all unread messages.
- Save the original
.emland the plain text first, before doing anything else with the message. - Check the language. When the target is Chinese, the tool measures how much of the body is Chinese; for other targets it uses langdetect. Anything not in the target language goes through a free translation engine; if that fails, it carries on with the original.
- Pull material, size, quantity and process keywords out of the body.
- Price it. Orders of 50 or more use the bulk rate, otherwise the retail rate; the base price is multiplied by the size coefficient, process fees are added, then the result is multiplied by quantity and by the quantity discount.
- Draft the reply. If the original wasn’t in Chinese, it writes an English copy too.
- If the material or size is missing, it doesn’t quote: it writes a “manual handling” note listing what it did recognise.
The README has an example: ten crystal prizes, 20cm across, with UV printing and a wooden box. Using the example rules, the total comes to ¥1567.50.
Each step’s files go into their own folder: original emails, extracted text, translations and quotes. You can run it once by hand, or as a background service that checks every 30 minutes by default.
Three trade-offs
Save first, then process. The original is written to disk before translation or pricing. If something breaks, the original is still there.
Pricing rules live in code. Material prices, size coefficients, process fees and discounts are all in quote_calculator.py. The upside is that the rules can be versioned and the calculation is easy to follow; the cost is that changing a rule means editing Python, which isn’t something a non-technical person should have to do often.
Translation uses a free engine by default. The default is googletrans, which needs no key. It is an unofficial wrapper, and its reliability isn’t under our control.
What to sort out before going live
- The mailbox needs IMAP enabled and an app password; the login password won’t work. The README lists the server addresses for QQ Mail, 163, Gmail and Outlook.
- NetEase 163 requires the IMAP client identifier, or its security check blocks the login with “Unsafe Login”. The connection code already sends it.
- The pricing data has to be yours: the price table, size coefficients, process fees and discounts are in
quote_calculator.py; the mailbox, storage path and company details are inconfig/config.py. - The delivery promises in the quote template are written in code — sample turnaround, damage replacement and the free-shipping threshold. Change them to promises you can keep.
Who it’s for
It suits a small team whose quoting rules are fairly stable, whose enquiries arrive mainly by email, and who are willing to self-host a script.
It doesn’t suit a business whose rules change often, or that has no fixed formula. Neither does anyone who needs a web interface and multi-user collaboration. It is a self-hosted script, not a hosted service.
What this means for working together
- Look at the rules before talking automation. If the rules can be written as a formula, automating them is worth something.
- The machine drafts; a person confirms. Nothing goes out without someone looking at it.
- Keep the original, the translation and the quote. You can go back and check later.
- Spell out what has to be ready before launch. Don’t leave the client to guess.
If your enquiries follow fixed quoting rules, send me the rules and I’ll see whether they can be written as code. The first conversation is free, and there’s no obligation.