Resize and compress image attachments in .eml files to reduce email size without losing content.
This Python script processes .eml email files and reduces the size of embedded image attachments (JPEG) by resizing and compressing them. Ideal for archiving or reducing email storage without losing the original message structure.
- Resizes images to a maximum of 1920Γ1080 (customizable)
- Compresses JPEGs with adjustable quality
- Keeps all headers and body content intact
- Processes multipart email structures correctly
- Outputs a modified
.emlfile with reduced attachment sizes
If you have .eml emails with large photo attachments (3β5 MB each) or large inline (embedded) images, this tool can shrink the total email size by over 90% β perfect for reducing IMAP storage, backups, or long-term archiving.
Dependencies: pip install pillow piexif
1. Export the email Drag an email out of your email client (e.g. Thunderbird, Outlook) and drop it into a folder on your computer as a .eml file. Make sure itβs named like original.eml.
2. Run the script python python email_resizer.py This will:
Load original.eml
Resize all image attachments (if needed)
Save a new email file: resized.eml
3. Replace the email in your client Delete the original email (optional, to save space)
Import resized.eml back into your email client (e.g., drag it into a folder)
π Notes Only works on .eml files (RFC 822 format, supported by most clients)
The body, subject, sender, and all text content remain unchanged
EXIF metadata is preserved, and image orientation is corrected
π Why This Matters
Cloud email providers (like Gmail, Outlook.com) do not provide easy tools to reduce email size. They may even make it intentionally difficult to modify existing emails, especially if you're reaching storage limits. This tool gives you back control.
| Original | After Resize |
|---|---|
26 MB .eml with 6 full-res photos |
2.1 MB .eml, identical appearance |
| Images: 4000x3000, 3β4 MB each | Resized to 1920x1080, ~100β200 KB each |
π© Loading email: original.eml
π Processing email parts...
π¦ Multipart type: multipart/mixed
> π¦ Multipart type: multipart/alternative
> π Part: text/plain | Disposition: None | Filename: None
> β
Not a target for resizing, keeping original.
> π Part: text/html | Disposition: None | Filename: None
> β
Not a target for resizing, keeping original.
>π Part: image/jpeg | Disposition: attachment | Filename: P2290832.JPG
>π οΈ Processing attachment: P2290832.JPG
> Original size: 3573 KB
> Resized to: 1440x1080
> New size: 90 KB
>π Part: image/jpeg | Disposition: attachment | Filename: P2290835.JPG
>π οΈ Processing attachment: P2290835.JPG
> Original size: 3014 KB
> Resized to: 1440x1080
> New size: 176 KB
>π Part: image/jpeg | Disposition: attachment | Filename: P2290836.JPG
>π οΈ Processing attachment: P2290836.JPG
> Original size: 3101 KB
> Resized to: 1440x1080
> New size: 204 KB
>π Part: image/jpeg | Disposition: attachment | Filename: P2290824.JPG
>π οΈ Processing attachment: P2290824.JPG
> Original size: 3042 KB
> Resized to: 1440x1080
> New size: 191 KB
>π Part: image/jpeg | Disposition: attachment | Filename: P2290825.JPG
>π οΈ Processing attachment: P2290825.JPG
> Original size: 2991 KB
> Resized to: 1440x1080
> New size: 196 KB
>π Part: image/jpeg | Disposition: attachment | Filename: P2290829.JPG
>π οΈ Processing attachment: P2290829.JPG
> Original size: 2978 KB
> Resized to: 1440x1080
> New size: 169 KB
