[Python] how to get the embedded email from a email file?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I’m automating a process to get .msg files and extract all its information, the body in a PDF, and its the attachments. Some of them have another email embedded, but I couldn’t get the way to extract that attachment (outlook file) and repeat the process like the initial msg file, get its body in a PDF and extract its own attachments if is the case.

    Thank you.

    I’m using python for this and so far, this is the better way that I’ve found.

    file_path = Path(dest_folder) / file_name
    attachment.save(customPath=str(file_path))
    if file_path.exists() and file_path.stat().st_size > 0:
    ext_files.append(str(file_path))
    print(f"✓ Extracted with save(): {file_name}")
    else:
    print(f"✗ File saved but empty: {file_name}")


    What I’m getting is "✗ File saved but empty: {file_name}” and a folder with all the attachments on it and the body email in a TXT file.

    Continue reading...

Compartilhe esta Página