Introducción

Aspose.Email FOSS for Python is now available on PyPI: a free, MIT-licensed library for creating, reading, and converting Outlook .msg archivos completamente en Python, sin dependencia de Microsoft Office ni de ninguna extensión nativa. Instálalo con pip install aspose-email-foss>=26.3 y comienza a trabajar con contenedores MSG y CFB de inmediato.

La biblioteca está dirigida a Python 3.10 y versiones posteriores. Implementa el formato Compound File Binary (CFB) y el formato de mensaje MSG desde cero, brindándote un control determinista sobre cómo se serializan y leen los correos electrónicos. Debido a que la implementación es pura Python, se ejecuta idénticamente en Windows, macOS, Linux y en entornos contenedorizados.

Aspose.Email FOSS is designed for developers building email processing pipelines, compliance archival tools, forensic analysis workflows, or any application that needs to create or inspect Outlook-compatible message files without a running Exchange or Outlook installation.


Características clave

Crear archivos MSG

Construye compatibles con Outlook .msg archivos desde cero usando MapiMessage.create(). Establece propiedades MAPI estándar como asunto, remitente, hora de entrega y campos de visualización a través del PropertyId enum. Añade destinatarios con add_recipient() y archivos adjuntos con add_attachment(), luego guarda el resultado en disco.

from aspose.email_foss import msg

message = msg.MapiMessage.create(
    "Quarterly status update and rollout plan",
    "Hello team,\n\nPlease find the latest rollout summary attached.\n\nRegards,\nEngineering",
)

message.set_property(msg.PropertyId.SENDER_NAME, "Build Agent")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "build.agent@example.com")
message.set_property(msg.PropertyId.INTERNET_MESSAGE_ID, "<example-001@example.com>")

message.add_recipient("alice@example.com", display_name="Alice Example")
message.add_recipient("bob@example.com", display_name="Bob Example")
message.add_recipient(
    "carol@example.com",
    display_name="Carol Example",
    recipient_type=msg.RECIPIENT_TYPE_CC,
)

message.add_attachment("hello.txt", b"sample attachment\n", mime_type="text/plain")
message.save("example-message.msg")

Leer y convertir MSG a EML

Carga un .msg archivo con MapiMessage.from_file() y conviértelo a un Python estándar EmailMessage objeto a través de to_email_message(). Desde allí, serializa a bytes EML para almacenamiento o reenvío a través de SMTP.

from aspose.email_foss import msg

with msg.MapiMessage.from_file("example-message.msg") as loaded:
    email_message = loaded.to_email_message()
    eml_bytes = email_message.as_bytes()

with open("example-message.eml", "wb") as f:
    f.write(eml_bytes)

Inspeccionar el interior de MSG

Utiliza MsgReader y su subyacente CFBReader para inspeccionar la estructura binaria de un archivo MSG. Accede a los metadatos CFB (versión, tamaño de sector, recuento de entradas de directorio) e itera sobre las entradas de propiedades MAPI a nivel binario.

from aspose.email_foss import msg

reader = msg.MsgReader.from_file("example-message.msg")
cfb = reader.cfb_reader

print(f"CFB major_version={cfb.major_version}")
print(f"sector_size={cfb.sector_size}")
print(f"directory_entries={cfb.directory_entry_count}")

for entry in reader.iter_top_level_fixed_length_properties():
    tag = entry.property_tag
    print(f"tag=0x{tag:08X} flags=0x{entry.flags:08X} value={entry.value.hex()}")

reader.close()

Acceso CFB de bajo nivel

Lee y recorre cualquier contenedor Compound File Binary usando CFBReader. Enumera almacenes y flujos, resuelve rutas por nombre y extrae datos de flujo sin procesar para procesamiento personalizado.

from aspose.email_foss.cfb import CFBReader

reader = CFBReader.from_file("example-message.msg")

for entry in reader.iter_storages():
    print(f"Storage: {entry.name}")

for entry in reader.iter_streams():
    data = reader.get_stream_data(entry.stream_id)
    print(f"Stream: {entry.name} size={len(data)}")

reader.close()

Inicio rápido

Instala la biblioteca y crea tu primer archivo MSG en menos de diez líneas:

pip install aspose-email-foss>=26.3
from aspose.email_foss import msg

message = msg.MapiMessage.create("Hello from Python", "This is a test message.")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "sender@example.com")
message.add_recipient("recipient@example.com", display_name="Recipient")
message.save("hello.msg")

with msg.MapiMessage.from_file("hello.msg") as loaded:
    eml = loaded.to_email_message()
    print(eml["Subject"])

Formatos compatibles

FormatoImportarExportar
MSG
CFB

Código abierto y licencias

Aspose.Email FOSS for Python is released under the MIT License. Puede usarlo en proyectos personales, internos y comerciales sin restricción. El código fuente está disponible en GitHub.


Comenzando