Make AI Agents (New)
Create AI agents for different...
Mailhook-triggered AI agent
10 min
this mailhook triggered ai agent scenario watches for new emails, and the agent replies to them mailhooks (email webhooks) immediately trigger {{scenario plural lowercase}} in response to new emails, rather than docid\ sclqhrvey8nqgrtm5amnp prerequisites two email accounts, such as a business email address and a personal email address this example uses gmail if you have a different email provider, see its documentation for equivalent settings in the relevant steps step 1 add a custom mailhook module the webhooks > custom mailhook module generates an email address (mailhook) that your email provider forwards new emails to, triggering the {{scenario singular lowercase}} to add a custom mailhook module in the {{scenario singular}} builder, in the top left corner, name your {{scenario singular lowercase}} and click save click the giant plus in the app search, search for and click webhooks select the custom mailhook module in the module settings, in mailhook , click add in webhook name , name the mailhook for example, use the {{scenario singular lowercase}} name click save you'll now see the generated mailhook to use in later steps copy the address to your clipboard and click save you'll later update your email settings to forward emails to it click save in the {{scenario singular}} toolbar you've now added a webhooks > custom mailhook module step 2 add your mailhook as a forwarding email in the email account where new emails trigger the {{scenario singular lowercase}} , add the mailhook as a forwarding address so your email provider sends new emails to it to add the mailhook as a forwarding address open your gmail account click the settings icon in the top right menu, and click see all settings go to the forwarding and pop/imap tab click add a forwarding address paste the mailhook that you copied earlier agree to proceed in all remaining steps you've now added the mailhook as a forwarding address in gmail step 3 create an email filter to send only specific incoming emails to the mailhook, rather than all emails, create a filter in gmail to create an email filter in settings in your gmail account, go to the filters and blocked addresses tab click create a new filter in from , enter the email address associated with the email account that you're in now you use your own email address so you can send yourself an email and reply to it your email reply passes an important header into {{product name}} called references that you must map later in the {{scenario singular lowercase}} click create filter select forward it to and select the mailhook that you added in the previous step click create filter you've now created an email filter, so only specific emails go to the mailhook step 4 send a test email to the custom mailhook module to test that your custom mailhook module receives forwarded emails from gmail in the {{scenario singular}} builder, click run once on the {{scenario singular}} toolbar in gmail, send yourself an email once the mailhook receives the email, you can click the output bubble of the custom mailhook module to view the email properties, such as headers you've now sent a test email to yourself next, reply to it step 5 reply to the test email reply to the first test email to pass headers that are only available in email replies — in reply to and references —into the {{scenario singular lowercase}} for mapping you'll need these values for replying to emails to reply to the test email click run once on the {{scenario singular}} toolbar go to your gmail account reply to the email that you sent yourself once the mailhook receives the email, click the output bubble to expand headers and view the values you'll use in later steps message id the unique id of an email in reply to the message id of the email being replied to references a list of message ids in a single thread of emails, with the first id being the initial email the webhooks > custom mailhook is complete now that it has reply email output data step 6 add a run an agent module to add the make ai agents (new) > run an agent module click the plus icon next to the webhooks > custom mailhook module in the app search, search and click make ai agents (new) click the run an agent module in connection , select an existing ai provider connection from the dropdown or click add to add a new one if you don't want to create an account with an ai provider, select make's ai provider in model , select a model from your chosen ai provider in instructions , describe who the agent is and what it does alternatively, copy paste the following you are a helpful agent who replies to emails in input , tell the agent to read the email content and answer in html you can copy paste the following read the content of this email \</content> text \</content>, and answer in html format directly reply to the email don't add any internal instructions or provide an email signature while optional, xml tags (\</content>) clearly separate data ( text ) from the rest of the instructions replace text with the text value from the webhooks > custom mailhook module in conversation id , enter the following function ifempty( first( split( headers references ; space ) ) ; headers message id ) this function uses the first message id listed in the reference header, and if empty, uses the message id the split( splits the reference array into individual values and the first( uses the first value replace the text in the function (headers reference and headers message id) with the corresponding values from the webhooks > custom mailhook module click save in the {{scenario singular}} toolbar you've now added a run an agent (new) module step 7 add a send an email module the gmail > send an email module replies to emails with agent generated answers from the make ai agents (new) > run an agent module to add a send an email module click the plus icon next to the make ai agents (new) > run an agent module in the app search, search for gmail and click send an email in the module settings, in connection , select the gmail connection that you used to create the mailhook in to , map the sender email address value from the webhooks > custom mailhook module in subject , map the subject value from the webhooks > custom mailhook module in body type , select raw html because you requested html in the agent instructions in content , map the response value from the make ai agents (new) > run an agent module toggle advanced settings in additional email headers , add these email headers email header 1 in key , enter in reply to in value , map the headers message id value from the webhooks > custom mailhook module email header 2 in key , enter references in value , map the headers references and headers message id values from the webhooks > custom mailhook module click save click save on the {{scenario singular}} toolbar your email webhook triggered ai agent {{scenario singular lowercase}} is now ready to test again step 8 update the email filter and test it based on your current email settings, gmail forwards emails from yourself—including agent replies to them—to the mailhook to prevent an infinite loop, where each agent reply triggers the {{scenario singular lowercase}} , add a different email address to your email filter, such as your personal email address, and test it from that account to update the email filter and test it in gmail, click the settings icon, and click see all settings click filters and blocked addresses find your existing email filter and click edit in from , add a different email address click continue , then click update filter in the email account associated with the new address, send an email to the original email address in the {{scenario singular}} builder, click run once on the {{scenario singular}} toolbar to test if agent replies work return to the account associated with the new email address you now have an email thread with the initial email ( 1 ) and the agent reply ( 2 ) you've now created a mailhook triggered ai agent {{scenario singular lowercase}} , where your target email account forwards emails to a mailhook, and the agent immediately replies to them next, you can tailor the email filter with additional specifics, depending on your use case