<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to send an email with an attached file from notebook in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383808#M6585</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="686932" data-lia-user-login="amaaiia" class="lia-mention lia-mention-user"&gt;amaaiia&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You don’t need a traditional Azure Blob Storage connection string to access files from another lakehouse in Fabric. Each Fabric lakehouse is stored in OneLake, and you can directly mount it to your notebook session using its ABFS path. Then you can open the file from the local mount path and attach it to your email. For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from notebookutils import mssparkutils&lt;/P&gt;&lt;P&gt;# Provide the workspace and lakehouse IDs of the lakehouse you want to read&lt;BR /&gt;workspace_id = "&amp;lt;YOUR_WORKSPACE_ID&amp;gt;"&lt;BR /&gt;lakehouse_id = "&amp;lt;YOUR_LAKEHOUSE_ID&amp;gt;"&lt;/P&gt;&lt;P&gt;# Construct the ABFS path for the target lakehouse&lt;BR /&gt;abfs_path = f"abfss://{workspace_id}@onelake.dfs.fabric.microsoft.com/{lakehouse_id}"&lt;/P&gt;&lt;P&gt;# Mount the lakehouse to a local folder in your notebook&lt;BR /&gt;mount_point = "/mnt/external_lakehouse"&lt;BR /&gt;mssparkutils.fs.mount(abfs_path, mount_point)&lt;/P&gt;&lt;P&gt;# Use the mounted path to open the file&lt;BR /&gt;local_file_path = f"{mount_point}/Files/path/to/file.xlsx"&lt;BR /&gt;attachment = open(local_file_path, "rb")&lt;/P&gt;&lt;P&gt;# Your email sending logic&lt;BR /&gt;send_email(&lt;BR /&gt;subject="File from another lakehouse",&lt;BR /&gt;body="See attached",&lt;BR /&gt;attachment_content=attachment.read(),&lt;BR /&gt;attachment_name="file.xlsx"&lt;BR /&gt;)&lt;BR /&gt;attachment.close()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please give it a try and let me if this works&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/microsoft-spark-utilities" target="_blank"&gt;https://learn.microsoft.com/en-us/fabric/data-engineering/microsoft-spark-utilities&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2025 07:45:16 GMT</pubDate>
    <dc:creator>nilendraFabric</dc:creator>
    <dc:date>2025-01-28T07:45:16Z</dc:date>
    <item>
      <title>How to send an email with an attached file from notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383786#M6583</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a notebook with the code to send an email. The email can be send with an attached file. My code is able to send an attached file located in Files/emails path of the default lakehouse on the notebook.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;attachment = open(relative_attachment_path, 'rb')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to change the code so I can be able to attach a file located in any lakehouse (not the default one), providing the workspace_id and the lakehouse_id. I've seen this piece of code, I dont' know if it will work, but I don't know which is the connection string of the blob storage. Where can I get it? I don't have a storage account in Azure for Fabric.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Configure Azure Blob Storage client
connection_string = 'your_connection_string'
container_name = f'workspace-{workspace_id}-lakehouse-{lakehouse_id}'
blob_name = 'path/to/file.xlsx'

blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)

# Download the file from lakehouse
downloader = blob_client.download_blob()
file_content = downloader.readall()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 07:34:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383786#M6583</guid>
      <dc:creator>amaaiia</dc:creator>
      <dc:date>2025-01-28T07:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email with an attached file from notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383808#M6585</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="686932" data-lia-user-login="amaaiia" class="lia-mention lia-mention-user"&gt;amaaiia&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You don’t need a traditional Azure Blob Storage connection string to access files from another lakehouse in Fabric. Each Fabric lakehouse is stored in OneLake, and you can directly mount it to your notebook session using its ABFS path. Then you can open the file from the local mount path and attach it to your email. For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from notebookutils import mssparkutils&lt;/P&gt;&lt;P&gt;# Provide the workspace and lakehouse IDs of the lakehouse you want to read&lt;BR /&gt;workspace_id = "&amp;lt;YOUR_WORKSPACE_ID&amp;gt;"&lt;BR /&gt;lakehouse_id = "&amp;lt;YOUR_LAKEHOUSE_ID&amp;gt;"&lt;/P&gt;&lt;P&gt;# Construct the ABFS path for the target lakehouse&lt;BR /&gt;abfs_path = f"abfss://{workspace_id}@onelake.dfs.fabric.microsoft.com/{lakehouse_id}"&lt;/P&gt;&lt;P&gt;# Mount the lakehouse to a local folder in your notebook&lt;BR /&gt;mount_point = "/mnt/external_lakehouse"&lt;BR /&gt;mssparkutils.fs.mount(abfs_path, mount_point)&lt;/P&gt;&lt;P&gt;# Use the mounted path to open the file&lt;BR /&gt;local_file_path = f"{mount_point}/Files/path/to/file.xlsx"&lt;BR /&gt;attachment = open(local_file_path, "rb")&lt;/P&gt;&lt;P&gt;# Your email sending logic&lt;BR /&gt;send_email(&lt;BR /&gt;subject="File from another lakehouse",&lt;BR /&gt;body="See attached",&lt;BR /&gt;attachment_content=attachment.read(),&lt;BR /&gt;attachment_name="file.xlsx"&lt;BR /&gt;)&lt;BR /&gt;attachment.close()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please give it a try and let me if this works&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/microsoft-spark-utilities" target="_blank"&gt;https://learn.microsoft.com/en-us/fabric/data-engineering/microsoft-spark-utilities&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 07:45:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383808#M6585</guid>
      <dc:creator>nilendraFabric</dc:creator>
      <dc:date>2025-01-28T07:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email with an attached file from notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383874#M6589</link>
      <description>&lt;P&gt;It works BUT:&lt;/P&gt;
&lt;P&gt;1. Instead of:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;local_file_path = f"{mount_point}/Files/path/to/file.xlsx"
attachment = open(local_file_path, "rb")&lt;/LI-CODE&gt;
&lt;P&gt;You need to read the absolute path, and the notebook_id should be added. That is, when you mount the lakehouse to /mnt/external_lakehouse, the truth is that is being mounted to:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&lt;STRONG&gt;/synfs/notebook/{notebook_id}&lt;/STRONG&gt;/mnt/external_lakehouse&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 28 Jan 2025 08:34:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383874#M6589</guid>
      <dc:creator>amaaiia</dc:creator>
      <dc:date>2025-01-28T08:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email with an attached file from notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383907#M6593</link>
      <description>&lt;P&gt;Great insights&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="686932" data-lia-user-login="amaaiia" class="lia-mention lia-mention-user"&gt;amaaiia&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 08:47:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-send-an-email-with-an-attached-file-from-notebook/m-p/4383907#M6593</guid>
      <dc:creator>nilendraFabric</dc:creator>
      <dc:date>2025-01-28T08:47:14Z</dc:date>
    </item>
  </channel>
</rss>

