Now let's use Resend to add the email node to our project. Using the link on the screen, you can get onto their website and the link simply lets them know that you came from this video. Once you create an account, go inside of API keys and create a new API key. Make sure to give it full access and all domains. Then copy your key and add it to the environment file under the name Resend API key.
Then go inside of the documentation and scroll down until you find Build with AI section. In here you can find the Agent Skills. Make sure that you select Resend Skill as that is the one we have to install. Then go ahead and execute it in your terminal within your project. You will now be asked which skills to install.
So we are not going to need the agent email inbox, we are not going to need email best practices nor the react email, we just need the resend itself, which is basically the SDK, which we're going to use to programmatically send emails using resend node. Make sure to select your coding agent and make sure to select the project installation scope and use the symbolic link and proceed with the installation. Then go ahead and perform a git add and git commit so you don't have 23 changes in here and you can more closely and precisely follow the actual changes we're going to do to our code base. Now make sure to perform a reload skills and reload window if you're using a graphical interface and check if you have the recent skill available. Now let's prompt the following.
Set up recent SDK client inside of my lib folder in the project root. Use the recent skill. You should have the following changes. A new package added to the package.json and a resend lib located inside of the lib folder right next to where live blocks lives. You should import resend and very simply export a new instance of Resend using the Resend API key which we've added in our .environment.local so just make sure that it isn't misspelled.
Now let's construct a prompt to create this into a node. As always this prompt is available in the specification file in the specs folder called after chapter 20 email node. First add a send email action node that sends an email through resend. No browser session, so it doesn't use stagehand. So we purposely say this because all other nodes so far have been using stagehand.
So just in case the agent looks through those nodes and thinks, oh, so I need to use stagehand, let's make sure that it doesn't use stagehand explicitly. It has three fields, a recipient or to, like to whom we are sending, a subject and a multi-line body. When it runs, send an email with our existing Resend client from the hard-coded address onboarding at resend.dev. So unless you purchase a domain and add it to Resend and I think you need to be on their pro plan, you need to send emails through this domain. They don't allow sending it from any custom domains, which is perfectly fine for development.
Surface the sent email's ID as an output so downstream nodes can reference it. Resend's send returns data and error and doesn't throw on API error. If there's an error, throw so the Run marks this step as failed. Otherwise the node would look successful even when the email is never sent. Follow our convention for writing a node and use the resend skill.
You should now have a new implementation executor inside of the nodes folder which uses our resend client library, calls the function sendEmail, accepts to subject and body which are all strings, extracts data and error using awaitResendEmails.send, hardcodes from to be onboarding at resend.dev because we need this in development, then passes along the dynamic to subject and HTML as the body. In case there's an error or there's no data, go ahead and manually throw an error so we properly register this as a failed node and if successful go ahead and simply return data ID. Make sure that you also have a new node registered in the node registry, same as in the node executor. Go ahead and construct a workflow which ends in some kind of extract node and then attach your new send email node to this extract node. Make the subject be something of relevance to whatever is in the extract node, same in the body and then find the connection for that extract node and interpolate its extraction.
And for the to property, you need to enter the email in which you are logged in into your resend account. So in development, you cannot send emails anywhere besides your own account which you are logged in with. So make sure you use that account. You should also see all of that information in the node itself and then go ahead and run the workflow. Now go inside of the Resend dashboard under Emails and in the Sending tab you will see exactly which email you have sent.
As you can see, tutorial mailing is the address as I've entered, subject is author information and inside I can see the about section of Albert Einstein and we can find the same email in our Gmail inbox. And now let's go ahead and stage, commit and push our changes.