◈ Mail → Excel

Email to CSV (not Excel)

By the Mail → Excel team · Updated 2026-10-18

CSV is the right output when the file has to be imported somewhere: CRM, BI, a script. Excel adds formatting you do not need.

Field mapping that avoids pain later

ColumnFormatWhy
dateISO 8601 (2026-10-19T10:30:00Z)Sortable, unambiguous timezone
from_nametextDisplay
from_emaillowercase email onlyJoins and dedupe
subjecttext, quotes escapedSearch
foldertextPreserve source
has_attachments0/1Filter in CRM

Working export to CSV

import csv, email, imaplib

imap = imaplib.IMAP4_SSL("imap.example.com")
imap.login("user@example.com", "APP_PASSWORD")
imap.select("INBOX", readonly=True)
status, data = imap.search(None, "(SINCE 01-Sep-2026)")

with open("mail.csv", "w", newline="", encoding="utf-8-sig") as f:
    writer = csv.writer(f)
    writer.writerow(["date", "from_email", "subject", "folder", "has_attachments"])
    for num in data[0].split():
        status, msg_data = imap.fetch(num, "(RFC822)")
        msg = email.message_from_bytes(msg_data[0][1])
        writer.writerow([
            msg["Date"],
            email.utils.parseaddr(msg["From"])[1].lower(),
            msg["Subject"],
            "INBOX",
            int(any(p.get_filename() for p in msg.walk())),
        ])

Encoding rules

Excel vs CSV

CSVExcel
CRM / BI import✅ nativeneeds conversion
Human readingplain✅ formatting, filters
Formulas, multiple sheets❌✅
File sizesmallerlarger

If you need both, generate CSV and XLSX from the same data in one pass.

FAQ

Why does Excel show garbled text in my CSV?

The file is UTF-8 without BOM. Save with utf-8-sig or import via Data → From Text/CSV and choose UTF-8.

Can I import email CSV into a CRM?

Yes, map CSV columns to CRM fields. Keep email addresses lowercase and dates in ISO 8601 to avoid import errors.

Related guides