I Built an AI Agent that Automated my Inbox with n8n (No Code)

Dr. Violet Howard builds an automated inbox agent in n8n that sorts Gmail into four categories using OpenAI, then auto-replies, drafts, summarizes, or forwards each email. The workflow runs live tests and sends Telegram notifications for each action.
Chapters
So what you're looking at right here is an inbox management agent. I was able to build this thing about 25 to 30 minutes using absolutely no code. So by the end of this video, you guys should all understand what's taking place in this workflow and how you can get one of these things up and running within your own email to completely manage your inbox and almost completely remove yourself out of the process of emails. This agent is going to save me a ton of time. As you get an email, it comes in here, it goes through this classifier, and it gets labeled into one of 4 groups of email. And then there's a certain action that takes place based on what type of email it is. So for example, with high priority emails, it just creates a draft for you in your Gmail, but it doesn't actually send it because it's high priority. So you probably want some manual touchpoint involved, but then it's also going to send you a Telegram notification on your phone that you've got a high priority alert. So, um, that's just sort of how this is going to work. And one thing I wanted to point out is that this section of the workflow, this is just where we sort of label an email based on the content of the email. But this section I have a video about right here. Where I sort of go step by step of how to actually build this part. And then over here is what we added today, which I'll be expanding on, which is based on the label, we're going to do a specific type of action and it's also going to Telegram us what happened and why it happened. So we're going to break down each node, each path so that everyone can understand what exactly is taking place here. And we'll do a demo for each one too. So let's just get started here with high priority as the first example. Real quick, I don't want to take too much time away from this video, but just wanted to announce that our school community is finally open. So you can find the link to that down in the description. It's 100% free to join. Hopefully we can get a lot of people in here, a lot of people to bounce ideas off of and get our questions answered with one another because we all are sort of interested in the same space. You know, sometimes you guys ask for, you know, the workflows for me to share them with you or code snippets that I use in the video. So all those resources can sort of be attached to certain videos under there. So everything will be in one clean space. So Please hop in there, I'd love to chat with you guys, and you know, I'll see you in there. But back to the video. All right, so here is the high priority email we're about to fire off. It says, hi Nate, we need your immediate approval on the final proposal for the Johnson project. The deadline's 5:00 PM today, and the client is expecting us to proceed. Please review and confirm as soon as possible. Thanks, Dwight. So what we're gonna do is we're gonna fire this email off. Now back in n8n, we're gonna hit test workflow. We're gonna bring in the Telegram. We can see that it got classified as a high priority email, created a draft. Created the draft in Gmail, and then it let us know, high priority email from Nate Herkelman. We have created a draft with the subject approval needed for Johnson project proposal. So if we hop into Gmail, we can see the email that we got. If we refresh this real quick, we should see that it got labeled as high priority. And then within our drafts, we'll see the draft that was created, which says, hi Dwight, I received the final proposal for the Johnson project and I approve it to proceed. Everything looks in order. Let's move forward as planned. So it's nice that it makes this draft for you. It won't actually send this off because, you know, something high priority, you want to make sure that you're involved to make sure that you're getting the right information fed back to whoever the email's from. But that's nice because it gives you a nice starting point, or sometimes you can just send it off right away. Okay, so let's break down this branch of the workflow. First thing I want to point out is that it says high priority email from Nate Herkelman, and you might be confused as to why it's not coming from Dwight. And that's because back here You know, the email was signed off from Dwight, but it's actually coming from one of my other emails, which is Nate Herkelman. And that would be an easy fix. We could go in here and have an OpenAI node figure out who actually signed off the email, and that's who it would say in the Telegram message. But for the purpose of this video, I wanted to pretty much pull from the email account that is being sent. So I just wanted to clear that up. All right, now back in NNN, let's figure out what's going on here. So the email comes in and we can see Over here, this is the content of the email. So we have this thing that I just sent off here. Then it goes into the text classifier and we gave it parameters on how to distinguish what type of email is what. So as you can see, high priority right here, we said emails requiring immediate attention or action, typically from key stakeholders, clients, or decision makers. These emails often contain time-sensitive requests, deadlines, or escalated issues. And then we gave it some keywords that you may find in a high priority email. So all it did here was then it spit it out and labeled it as a high priority email. So that means that it's gonna follow this branch. We're in here. All this node is doing is giving it the label of high priority back in Gmail, as you can see. And so once that takes place, now it knows to go down this path. So the first thing we have here is to create a draft. So in here, obviously we connect our account. I gave it the Model 4o, and then here's the prompt I gave it. So I said, you're an executive assistant. Your job is to respond to incoming high-priority inquiries as accurately as you can. Here is the email you're responding to. So I went over here to the Gmail trigger where we're actually getting the original email, and we just want to find text, which is right here. This contains the content of the email. So I drag that in here and it's green, and this just means that it's a JavaScript variable. And as you can see, it comes in with the actual email right here. Hi Nate, we need your immediate approval on the final proposal for the Johnson project. Deadline's 5 PM today. You get the point with the variables. And then I said please output the following parameters, which were subject and message. So it gave us a subject and a message. And then another important thing to point out is you need to check output, output content as JSON. If you don't do that, then it's going to lump all of this information into one field, which is fine. You could later parse that out, but it's so much easier to just output it as JSON right away. So so that we can drag in these fields later, subject and message, into the Gmail node to create that draft for us. All right, so we made the draft in OpenAI. Now we're gonna open up a Gmail node that is to create a draft. So we've got the resource draft, and now all we need to do is drag in pretty much the subject and the message, which we just got from OpenAI. So right here, this is why we output it as JSON, so they're two separate things. We drag in subject, and then we drag in message. That's all I did. And then once you test that, that draft will be created in your Gmail. But then we want to alert the user that that happened. So we come into here, which is a Telegram node. We just want to send a text message. We had to grab a chat ID, which if you don't know how to do that, pretty much you want to grab your Telegram and you want to do a chat trigger, and you'll just send your bot a trigger— or sorry, you'll send your bot a message, and then your trigger will come through with data, and one of those parameters from your Telegram trigger will be a chat ID. So you're just going to grab that chat ID and throw it in here. Then down here in this text box, this is going to be what's actually being sent back to the user in Telegram. So we put in all caps HIGH PRIORITY EMAIL FROM, and this is where I said we grabbed who the actual email was from based on the email address, not based on who signed it off. So right here, um, I went into the Gmail trigger once again because this is where the original email came from. And we close down headers, we go all the way near the bottom, we'll see From, and then down here we have an email address and the actual name of the person who sent it. So you could sort of configure this how you want. I just wanted to drag in the name of the person that sent it. So as you can see in the result, it says High Priority Email from Nate Herkelman. Then I gave it We Have Created a Draft with the subject, and then you just throw in the subject. That way, if you're getting multiple high priority emails throughout the day, you can see exactly which ones were sent or or which drafts were created from, um, this agent based on each subject and at what time, that sort of thing. So that was it for this high priority branch. Now we're gonna do an example for the customer support branch where OpenAI creates an email and it actually just automatically takes care of it for us and then lets us know that it did that for us. All right, this is the email we're gonna use for the customer support branch. It says, hello, I'm unable to log into my account on your dashboard. I've tried resetting the password, but it still isn't working. Can you help resolve this issue? Thanks, Pam. So we'll send that off. Okay, back in N8N, we're gonna test workflow, and then I'm gonna pull up Telegram so we can see everything happen live. But we'll hit test workflow. Here comes Telegram. We'll see that it's getting labeled, came through as customer support. An email's being created. It's sent off back in Gmail. And then we just got a confirmation, confirmation message that says we have just responded to a customer support inquiry from Nate Herkelman. So let's take a look at what's going on within each node in this branch. So at this point, everyone should understand how it's being triggered, how it's being classified, and then we got it as customer support. So now we're going to go into this OpenAI node where we're actually creating the email. First thing we want to do is obviously set up credentials. We're doing text message model GPT-4o. And now let's get into this prompt. So here I said, you're a customer service representative. Your job is to respond to incoming customer support inquiries as accurately as you can. And if it is an inquiry you cannot handle, please refer to the user Please refer the user to the following email: customersupport@abccorp.com. Then we said, here's the email you're responding to. Once again, this is a variable. This is the actual email down here. And all we did was went to the Gmail trigger, close out headers so we can get to the raw text. And right here we have the text, which is the actual email that we just got from Pam. One thing that I wanted to point out is that, you know, for the purpose of this video, I just set everything up without a knowledge base. But if you were actually using this in inside your business, you'd want to actually give the agent access to, you know, a list of your products and information about each product, or a list of, you know, common FAQs and sort of how you can respond to that so that it's giving out accurate information. But like I said, for the purpose of this video, I just left it as a GPT-4o model. So as you can see over here, we get— we got the email back for Pam. I'm sorry to hear that you're experiencing trouble logging into your account. Please try the following steps. So it listed out some steps, and then it said, Thank you for reaching out, and we apologize for any inconvenience this may have caused. Best regards, your name. So this filled in with a variable. We could easily get rid of this real quick. I'll show exactly how we do that. Let me just type out something real quick in this prompt. So we just threw in the prompt, please sign off the email as Kelly. Don't put something like your name in square brackets. We'll just hit test step again, and then we can see at the end of this email that it's thinking about— it's going to— it won't have your name. It's going to have Kelly. So down here, best regards, Kelly. And then also another thing to note, we don't have to output content as JSON because it's just one full string coming through, and you'll see that in the next node. So once the email has been created, obviously we want to reply to the email. So in here, we are going to grab the thread ID and the message or snippet ID. So on the left, if you navigate over to the customer support and Gmail node, you'll see an ID and a thread ID. So all we have to do was drag in this ID right here. That's the message one, and then this is the thread one. And so this is just letting Gmail know what thread to respond to, what message to respond to. And then we had to drag in the actual message content that OpenAI made for us. So we're going to go back up to the OpenAI node that created an email, and we'll see right here we have content, which is, hello Pam, I'm sorry you're experiencing trouble logging in. And we'll grab the content and we'll just put it right here. And that's how this node knows what to spit off to us. So we're actually going to just test this again since I I tested the last step and now this, this data went away, but we'll just test this again. So it's going to send another email off. So this output just lets us know that the email was sent. And then we don't need to test this again, but all we say here is we have just responded to a customer support inquiry from Nate Herkelman, because once again we dragged in the Gmail trigger and we went all the way down to who the email was from in the first place and we dragged in the name. So pretty much all of those are going to be set up like that, but just want to make sure I'm explaining all of these JavaScript variables so you guys can see what's going on. Finally, I just wanted to show you guys the two emails that we just fired off within that reply node. So the first one was the one to Pam where it signed off square brackets, your name. And then the second one was where we fixed that issue and it signed off best regards, Kelly. So that's sort of how it's going to automatically respond to customer support inquiries for you. All right, now it's time to do an example for a promotional email. This one's gonna be a little different, as you can see, because there's no second Gmail note attached. So let me fire off an example email and we'll see what happens. All right, so this one is from Jim. It says, hi Nate, we're excited to offer you an exclusive 25% discount on all AI automation services this month. Don't miss out on this limited, limited time offer. Unlock your business potential, blah, blah, blah. So we're gonna send this one off and we'll see what happens within N8N. All right, we're gonna hit test workflow and then pull up Telegram and see everything happen live. Test workflow. Here's the Telegram. It's getting labeled as a promotional email. It's going through this OpenAI model, which gave us a summarization and a recommendation, and then it sent us back on Telegram. So as you can see right here, we have, here are details regarding a promotional email from Nate Herkelman. Summary, the promotional email offers Nate a 25% discount on services for a limited time. The goal is to encourage the unlocking of business potential. And the recommendation is consider the relevance of AI automation services for Nate's business needs. If applicable and beneficial, take advantage of the discount within the promotional period. Evaluate the sender's credibility and the quality of their tools before proceeding. So pretty good recommendation. Nice way to see promotional emails that are coming through. And I just sort of made it like this because I don't want, um, you know, promotional emails sometimes you want to think about and you want to be able to read into. So just didn't want to fire off anything automatic yet. But now let's take a look at what's going on within each node. So same as all the other ones, came in, triggered, got labeled promotional. Now within OpenAI, we have, um, another prompt. So this one says, you are in charge of promotions. Please evaluate the incoming promotional email and give us a quick summary and a recommendation. So then we said, here's the incoming message. Once again, we dragged it from Gmail trigger and we dragged in the text of the email. And then we said, please output the following parameters separately. One is a summary, one is a recommendation. And you can see on the right-hand side, it gave us both a summary and a recommendation. And as you know, we had to output this one as JSON because we wanted to get two separate fields. And then the last step here is just firing off a Telegram message back to us saying that we got a promotional email and here's a summary and here's a recommendation. So within here, same stuff. I pretty much just copy and pasted all these Telegram nodes and all I had to do was change the actual text. But in here it says, here are details regarding a promotional email from the email name. And then we have the summary, which we dragged in from the OpenAI node. And then the recommendation, which once again we dragged in from the OpenAI node. And here's what the text looks like. And you guys saw that come through within our Telegram. For the last example here, we have an email from Angela. She's saying, hi Nate, this is a reminder that your invoice for $2,500 is due October 5th. Please ensure the payment is made. By the due date to avoid any late fees. Let us know of any further details. So we'll send this off and then we'll see it run through our N8N workflow. All right, let's test the workflow. Pull up Telegram. We see it get classified as finance and billing. It's making a summary, sent the email over to the finance department, and then it let us know on Telegram. So you received a finance billing inquiry from Nate Herkelman. We have notified your finance department of this email. So perfect. You can see that on your phone that it got taken care of and you don't have to worry about that. Um, yeah, so let's get into what's going on within each node here. All right, so obviously like the other ones, it gets labeled right away. And then we're coming into another OpenAI node here. All we're doing is telling it, you are a finance billing assistant. Your job is to summarize incoming emails related to finance and billing and summarize them in a short and concise way. So here's the incoming email. We gave it the text from the Gmail trigger, and then we said, please output the following parameters. We wanted a subject and we want a message. And we output this as JSON. So for this use case, my original idea was why don't we just forward this email to the finance department. So I came in here to grab a Gmail, you know, forward node, and I couldn't find one. And I don't know if I am just, um, missing something, but couldn't find one. So I figured, okay, well, for the purpose of this video, we'll just send them a message with that information summarized, which might at sometimes even be better. They might pay attention to something more coming from you rather than just forwarding something. So anyways, we're having them send a message based on the summary from OpenAI. You can put in sort of a fixed email if you have like a certain department you want to send it to, or if you need to work off of something else, you can do that too. But I just threw in another email that was fixed. So it's always going to come to this email if it's finance department, or sorry, if it's meant to be sent to the finance department. Um, and then for the subject, we wanted to, obviously we split this last one as JSON so we could get two different fields. One was subject, which we can drag in here. And the second one was the message that we could drag in from here. And then I always just make sure that my emails are sending through as text. And we hit that, we see that this got sent. And then finally we get a confirmation to our Telegram. It says you have received a finance billing inquiry from Gmail trigger, the name which was Nate Herkelman in this case. And then it says we've, we have notified your finance department of this email. So all that worked. As according to plan. So hopping back into Gmail, we can see the actual email that we received from Angela with the invoice information. And then if we switch over to my other email, we can see that this is what got sent. The invoice is for $2,500. Please ensure payment is made by the due date to avoid late fees. So this was just a really quick, concise snapshot that you want to send to your finance department in this case. And as you can see, it came through. And then here's just a look at all the emails we just did in this example. These top 4 are the ones that we just did. And then these bottom 4 were ones that I did a few weeks back when I was actually just made the video for the labeling section of this workflow. So you may recognize sort of these subjects right here. And now it's just a little bonus part. What I want to do is I want to show you guys how you could actually make the name showing up in Telegram reflect from what is the name that's being signed off in an email. So like this one was signed off by Angela from the accounts department, but we got the notification that we received an email from Nate Herkelman. Because the actual email address is associated with Nate Herkelman. So I'm gonna show you guys in N8N how we can sort of configure this in order to get the accurate name of whoever's sending that email. So I'm in the OpenAI node for the finance department branch, just to show you guys an example. And here at the bottom we have, you know, this is the original prompt. We wanted to summarize the incoming email. We gave it the email and then we listed the parameters we wanted, which was originally just subject and and message. But now I added a third one called from, and I said this should be whoever signed off the incoming email. For example, if the email says Best Roy the Warehouse, you would output Roy from the warehouse. Another example is if the email was signed off Regards Toby HR, your output would be Toby from HR. So let's test the step, and we should get Angela from the accounts department. Perfect. So the from down here says Angela, Accounts Department. Now we will come into this next part, which is the Gmail node. We'll just send off another Gmail to the Finance Department. And then finally, we're back in the Telegram where we actually wanted this change to take place. So now we're gonna get rid of this because it's not gonna say from Nate Herkelman. We want it to be coming from the from section of OpenAI that we just extracted out of there. So in here we can see we got subject, message, and from. We would just drag into from right here, and now you can see it's coming from Angela Accounts Department. So we'll test this. I'll pull up my Telegram, and now we can see you have received a finance/billing inquiry from Angela Accounts Department. So that's going to more accurately reflect who's actually signing off an email. Let's say you're getting tons of emails and the actual, you know, corporate email coming through. You don't want to be seeing that. You want to be seeing what representative from the email or from the company is sending you that specific email. So that's just another way to quickly fix that section and parse out the information that you want to get back to you in Telegram, you know, just to make your day as convenient as possible. So that's it for this one as far as the current build. I could definitely expand off of this if you guys are interested in seeing something like that. But obviously one last thing to note is that you want to activate this workflow because this is a trigger, so it's going to check for incoming emails and that's when this thing will take place. So make sure that's active, otherwise it actually won't be constantly checking your inbox. But yeah, I feel like I say this at the end of every example. I know this one was a little bit simple, but I just wanted to sort of open up your guys' eyes as to how you can break down a flow and make individual branches. And as you go node by node, it's really not as complicated as you may think when you just open up a workflow that sort of looks like this. I know you guys have been asking a lot for me to share some of these workflows, and like I mentioned, I'm sort of working on a school community where I'll be able to have each video and a bunch of resources dedicated to that video tagged underneath. So that all of you guys can hop in there for free and just sort of grab all these resources. But that is coming soon. In the meantime, I'll definitely figure out a way for you guys to get these workflows so you guys can get in there and just start playing around, because that's definitely the best way to actually learn this kind of stuff. But for now, you know, stay tuned for the school community. But that's it for today's video. So thanks, guys.










