Automate Reading of MSExchange Email Attachments to Microsoft Fabric Lakehouse
59K views
Oct 30, 2023
This video demonstrated how to Automate Reading of MSExchange Email Attachments to Microsoft Fabric Lakehouse
View Video Transcript
0:00
Hello everyone this is Abiela David in this video I'm going to show us
0:08
how to automate the reading of Microsoft Exchange emails attack files into the
0:14
leghouse object of the synapse data engineering platform of Microsoft Fabric the data I'm going to read span from sales report 2013 to sales report 2016
0:27
Now these are the data in my exchange outlook. We can see 2013 to 2016
0:33
After we're able to successfully with data into the lake house, we're going to write a single query in the SQL endpoint of the lake house
0:44
And then I'm going to swipe to my Gmail address, send the sales report for the 2017 into this email
0:51
And then I'm going to go to the workspace we're going to create, refresh the data in the data
0:57
flow gen tool which is power query online go back finally to the SQL endpoint and execute the
1:05
code again and by so we should see the automation taking place in other roles the report for the
1:11
2017 would be included in the report so without much talking let's get started now this is the
1:19
Microsoft fabric welcome page so i'm going to go to my outlook again now these are the reports just
1:25
like I mentioned, each of the emails do contain an Excel book attachments
1:30
Now let's just see the content of the report 2016.xelSX. So these are all the columns and
1:36
of course we want to aggregate all the data across 2013 to 2016. So I'm going to close this
1:42
and come back to the fabric. Now the first thing I want to do is to create a workspace. So
1:47
I can click on the PowerBeer experience and then click on Workspaces and choose new workspace
1:53
Now I'm going to give this as data from exchange and I can give any name for your workspace
2:00
Click on Apply. All right so we can see the workspace is created
2:05
Now I'm going to switch to the data engineering experience of the Microsoft Fabric and click on Lakehouse
2:13
So I'm going to call this one sales repulse and click create
2:19
So we can go ahead and connect to the data source. So to do that, I can click on this Get Data and choose new Dataflow Gen 2
2:27
And that's going to open the Power Query Online where we can connect using different connectors
2:34
All right, so this is Dataflow 1 and this Power Quarry Online, which is quite amazing
2:39
Now it's a good practice to change the default Dataflow 1 to something meaningful
2:44
So I'm going to call this one sales data to be consolidated and click Enter to make the changes permanent
2:52
Now I'm going to click on get data and choose blank query because we're going to use the exchange dot content and function to access the content of my email
3:04
So go ahead and click on the next. So what I'm going to do for us is to remain this query
3:09
I'm going to call this yearly sales report and click enter. Now in the formula bar, I'm going to get rid of this and call the exchange dot content
3:22
M code open the bracket now I need to provide my email address with access the emails from
3:29
attack me from now this is my email address so you can see abeola at Exceljet consult
3:35
come on microsoft.com so I'm going to come here all right so this is my email address
3:43
now you're going to see credentials are required to connect to the exchange source so just
3:47
go ahead and click on configure connection okay so we're going to see
3:52
connect to data source now you'll see your exchange and the email address now we're going to connect
3:58
to our organizational account that's going to be the authentication kind so just go ahead and click on
4:04
connect amazing so we can see the different components of the exchange email now the first
4:10
i'm going to do is to filter out the calendar people task and meeting requests so click on the
4:18
filter or check all of them check mail and click okay Alright amazing now when I click on this I can see the different attributes the
4:33
columns in the table now I'm going to click on this expandable icon now we do
4:39
know need all of the columns we only need the photo path subject sender and I going to scroll down and I going to choose as attachments Now in other words when the e do contain attachments
4:53
And of course, I'm going to click on attachment itself, so go ahead and click on okay
4:58
Now we can see all the columns. I'm going to get rid of this first
5:02
I don't need this again and remove the columns after the right click
5:06
Now the first thing I want to do is let's just check the particular
5:10
Particulars of the sender now the email is actually coming from Abiladavid which is the name and the address is this
5:17
Yau email address now what I'm going to do is to click on this expandable icon because we want to see the names and
5:24
include some constraints or some filter on the address column so make sure this is checked and make sure if this is check automatically by any reason
5:33
uncheck this okay click okay okay so what I'm going to do is to only
5:40
check the email address that equal to abela.david 0.1 at yahoo.com so click on the filter drop down and uncheck all of them. I'm going to check the only one we need click okay. So that's a way of including the constraints or the rule to only return
6:00
folder that comes from or emails that comes from abela david. So I haven't done that now you can see in the photo path
6:10
now it can actually point not only to the inbox but including deleted items now in other words
6:16
if we have this kind of report deleted it's going to be included if we do not apply filter to the
6:23
photo path so i'm going to uncheck click on this filter button unchecked deleted items so it's
6:29
going to be looking into the inbox only go ahead and click okay amazing so we can see the
6:36
photo path is points to the inbox now for for the as attachments
6:42
Now we're going to set another rule by ensuring that only field that do contain attachments
6:49
are included in our data integration. So I'm going to choose equal to, now I'm going to choose drop down, yes, true rather
6:59
So in the case where we have false, it's going to be knocked off, so make sure it is checked
7:04
to true. And that's lovely. Now we can even go ahead and specify
7:10
keyword so I'm going to just text filters and I can say that contains now for the emails
7:16
now it must contain sales report keyword so I'm going to type in sales space report
7:22
and click on okay okay so I've been done all that I'm going to grab all these columns
7:29
hold down the shift key to the as attachment right click and choose remove columns
7:36
because we don't need them again all right now when I click on this I can see the different the different different different kind, I can see the different kind of the different kind of the different kind of the different kind of attributes
7:43
, I can see the different kind of attributes , the different kind of attributes, the different kind of attributes, such as the different kind of attributes
7:44
such as the name of the file, the file, extension, is in line, content, type, last
7:49
and so on and so on and so forth. Now I'm going to check this box, and we only need the names
7:57
name, extension, and the attachment, content itself. So we really check that three columns
8:04
Go ahead and click okay. We can see the data is now in binary file
8:09
binary file so this contains 2013 14 15 that's love now we can even further filter down
8:19
the extension to only pick dot excel s x so just text filters and that contains or we can
8:26
see that equals to and i'm going to choose dot xls x from the drop down click okay
8:34
do not need the two columns i'm going to pull down the shift key and click on the name
8:39
right click and then remove columns amazing so the last I want to do is to convert this
8:47
binary file into Excel workbook and of course promote the errors now I'm going to come
8:53
to the formula bar and use what's called table dot transform columns and functions
9:00
so I'm going to type that here carefully transform columns open the bracket and make sure the
9:08
the name is accurately typed table. Transform columns. I'm going to call you and put in a comment
9:13
I want to access the attachment content. So I'm going to open a square bracket and inside double code
9:18
I'm going to point to the attachments content. Make sure it is typed the way we have it here
9:25
And I going to come here put in a comment So I going to use the H Now the H we actually convert each of the binary file into Excel work books Now we going to come here put in the comments So I going to actually use the H So I going to actually use the H Now the H we actually going to convert each of the binary file into Excel Workbook Now we going to use the Excel
9:36
Workbook function in the bracket. Now, for the first argument, we're not going to point to the binary
9:42
So we're going to use the underscore, which points to the binary files
9:47
And they want to promote at the same time the headers. So I'm going to come outside here and close of the table
9:53
transform columns and click on this to commit and then the banner files will be converted into
10:00
excel standard workbooks so you can see we now have tables when i click on this i can see the
10:07
name the data itself the iron kind and hidden now i'm going to click on this expandable button now we are
10:16
interested in i'm going to uncheck all of them name and data now the other attribute not
10:23
it necessary so i'm going to click on okay okay and finally we're going to click on this expandable icon
10:32
and then we can see all the columns so the other date customer name city account manager
10:38
product price unit and sales amount now again if this is checked for any resume just
10:44
original column name as prefix please uncheck that go ahead and click okay amazing so we can see we have
10:52
the data combined and that's lovely. I'm going to right click on this name and remove columns
11:00
And the last thing I want to do is to assign appropriate data types. Now for this is
11:05
this edit value, I'm going to choose date data type. And then for the text, I'm going to grab
11:11
the customer name, hold down the shift key, click on the product column right click and choose
11:17
change type. I'm going to choose text. So we're going to change that to text data time
11:22
and that's lovely and let's put to the right for the columns such as the price and
11:28
sales amount I'm going to hold down the control key and click on the sales amount
11:33
right click and then change type want to choose currency data type and for the
11:38
units we're going to use the old number data type so I'm going to click on this icon
11:43
and choose whole number and those are the amazing transformative task that we're going to perform
11:50
in this exercise now the beautiful part of the power collier online is that we can see all the
11:56
steps in diagrams i'm going to collapse the data preview and this is the amazing steps that we've
12:03
been going through that's quite lovely now let's go to the tata preview and expand or maximize
12:10
now we are done with the transformative work we've renamed the query so in the past we're going
12:15
to see the ability to choose the destination here but that has been changed
12:20
in the lake hours so we can see so many changes coming up even as time goes on so the
12:27
destination is automatically pinpointed to leak out so we don't need to check that
12:33
or choose that again so I can go ahead and choose publish now or later let's go ahead
12:38
and publish now I can see the data flow staging lake outs the
12:45
datasets and for you can see the SQL endpoint and for the warehouse we can see the
12:50
default data set the warehouse and of course we can see the sales data to be
12:55
consolidated which is the data flow jet tool in other words the power query so if
13:00
there's a need to go back to the power query you're going to click on this particular
13:06
name and of course you can see this icon this icon tells you straight away that
13:10
this is power query online now let's go ahead and see the data in the SQL
13:17
endpoint where you can begin to write query against the data So click on the sales report
13:25
Amazing. So we can see the name of the schema. We can see the name of the database owner and the name of the table is
13:32
sales, jelly sales report. And then we can go ahead and of course we can even see
13:37
the data set which is quite amazing. Now let's just write the SQL query just like
13:43
you know we said. I'm going to click on new SQL query and that's going to
13:48
open the canvas for us to write. our query now let's just do select star from let's see all the content frost so I'm
13:57
going to grab this which is allowed and go ahead and click on run and that's going to
14:02
execute and return all the queries now the thing you want to do I'm going to just click
14:09
down I just move this down so that I can see what is going on now we actually want to aggregate or want to see the total sales amount generated for each of the year so we going to see from 2013 14 15 and 16 so I can say
14:25
select we use the year function to extract from the other dates I'm going to
14:31
call the other date underscore order underscore date close the bracket and I'm going to put
14:38
in a comment now I'm going to use this some aggregate function and let's check the name of the sales amount column so sales underscore amount okay
14:51
and I'm going to call it you know total sales amount click enter now I'm going to
14:59
specify that it's coming from now I can grab this coming from the yearly sales
15:05
report so I want to group by this year that we're going to extract I can control
15:11
and country v now let's go ahead and order by now let's order by the total sales amount
15:20
and let's do descending now that's fine let's go ahead and put it so I'm going to grab this
15:26
query and click on run amazing so we can see the report actually the name of the file the
15:34
name of the file in the sales report is actually 2012 so let's see it's really not 2013 so it is
15:41
2012 so I'm going to come back here so we can see report for 2012 we can see for
15:47
2015 2014 and 2016 which is amazing now I'm going to come to my Yahoo and this
15:55
is the report sales report for 2017 now I'm going to go ahead and click on send I'm
16:01
going to send it to my personal even address the abula at Exceljet
16:07
Consor triple one on Microsoft.com and go ahead and click on send
16:11
and let's check the exchange so let's just refresh which we see it's amazing so you
16:18
can see it just dropped in that's wonderful now you can see for now we do not
16:23
have 2017 included in this report okay we can even just okay let's just go ahead
16:29
so what I'm gonna do is I'm gonna come back to the workspace we created and just
16:35
like I said this is the power query and we can go ahead and click on refresh
16:41
now and then we're going to wait for the old step to incorporate the newly
16:50
received sales report 2017 now that can take some time depending on how
16:57
voluminous the data is like and just you know click on this icon to monitor
17:02
the refresh history so we're going to wait for some fee you can say it's going
17:07
in progress this status is in progress so you're just going to
17:11
wait for some field in a moment and then we should see succeeded so we're going to
17:17
wait and come back to this video amazing so we can see succeeded now it's
17:23
now being included we can go ahead and close this and click on that again and
17:29
then let's see the query that we just execute TED now I'm gonna scroll down
17:37
here I'm gonna scroll down and there I can see the query under the
17:41
my queries now that's actually story automatically which is quite amazing I'm
17:46
going to grab the query again and click on run and then we should be able to see
17:51
2017 sales report included now this is quite amazing because we are able to
17:59
include the data by sending to the exchange and then we refresh the whole
18:04
process in the power query online and then we execute the query again and that's
18:09
it we have 20 2017 report so the total sales for 2017 is 22,462 and I'm going to come to the email
18:20
a check I'm going to click on this and let's grab the sales amount column
18:25
control shift down our key now in the status bar we can see we have 23,000 four
18:30
six two which is quite amazing so this is basically how we can use or connect to data
18:38
in our exchange email get it on the power and into the lake house write SQL against that data sets and then include a new
18:47
data refresh the whole thing and then we see the data then included in the final
18:52
path so I hope you enjoyed this video if you do share with the friends comment
18:57
and give the thumbs up thank you and bye for now cheers
#Business & Productivity Software
#Email