Files
e90d007db3 Harrison/msg files (#2375)
Co-authored-by: Sahil Masand <masand.sahil@gmail.com>
Co-authored-by: Sahil Masand <masands@cbh.com.au>
2023-04-04 06:48:34 -07:00

4.5 KiB

Email

This notebook shows how to load email (.eml) and Microsoft Outlook (.msg) files.

Using Unstructured

In [1]:
from langchain.document_loaders import UnstructuredEmailLoader
In [2]:
loader = UnstructuredEmailLoader('example_data/fake-email.eml')
In [3]:
data = loader.load()
In [4]:
data
Out [4]:
[Document(page_content='This is a test email to use for unit tests.\n\nImportant points:\n\nRoses are red\n\nViolets are blue', lookup_str='', metadata={'source': 'example_data/fake-email.eml'}, lookup_index=0)]

Retain Elements

Under the hood, Unstructured creates different "elements" for different chunks of text. By default we combine those together, but you can easily keep that separation by specifying mode="elements".

In [5]:
loader = UnstructuredEmailLoader('example_data/fake-email.eml', mode="elements")
In [6]:
data = loader.load()
In [7]:
data[0]
Out [7]:
Document(page_content='This is a test email to use for unit tests.', lookup_str='', metadata={'source': 'example_data/fake-email.eml'}, lookup_index=0)

Using OutlookMessageLoader

In [8]:
from langchain.document_loaders import OutlookMessageLoader
In [9]:
loader = OutlookMessageLoader('example_data/fake-email.msg')
In [10]:
data = loader.load()
In [11]:
data[0]
Out [11]:
Document(page_content='This is a test email to experiment with the MS Outlook MSG Extractor\r\n\r\n\r\n-- \r\n\r\n\r\nKind regards\r\n\r\n\r\n\r\n\r\nBrian Zhou\r\n\r\n', metadata={'subject': 'Test for TIF files', 'sender': 'Brian Zhou <brizhou@gmail.com>', 'date': 'Mon, 18 Nov 2013 16:26:24 +0800'})
In [ ]: