Skip to main content

Does anyone have a current script that is parsing any emails beiing received in the new “trigger when email received”. I am trying to parse the body, but I cannot figure out the inputs from the email received.

I get errors on all of the inputs. My reason for the inputs, is that the receivedDate didn’t work.

// Get inputs from the automation
let inputConfig = input.config();
let subject = inputConfig.subject;
let body = inputConfig.body;
let receivedDateRaw = inputConfig.receivedDate;

// Optional: log inputs (for testing)
console.log("Raw receivedDate:", receivedDateRaw);
console.log("Subject:", subject);
console.log("Body:", body);

// Parse date string into Date object
let receivedDate = new Date(receivedDateRaw);

// ✅ Function to get the next Tuesday
function getNextTuesday(date) {
let day = date.getDay(); // Sunday = 0, Monday = 1, ..., Saturday = 6
let daysUntilTuesday = (9 - day) % 7;
if (daysUntilTuesday === 0) daysUntilTuesday = 7;

let nextTuesday = new Date(date);
nextTuesday.setDate(date.getDate() + daysUntilTuesday);

// Format as YYYY-MM-DD
return nextTuesday.toISOString().split("T")l0];
}

// ✅ Function to extract body up to signature
function extractMessageBody(text) {
let endIndex = text.indexOf("Jason Hill");
if (endIndex !== -1) {
return text.substring(0, endIndex).trim();
} else {
return text.trim();
}
}

// Final processed fields
let DateValue = getNextTuesday(receivedDate);
let Title = subject;
let Item = extractMessageBody(body);

// Output variables for next automation steps
output.set("Date", DateValue);
output.set("Title", Title);
output.set("Item", Item);

 

Could you provide an example email body as well as what you’d want the output of the parsing of that email body to be?


My goal is to forward an email to Airtable and to have the automation add it as a task in my database. I want the email subject to be added to the “Title” column, the date of the email to be added to the “Date” column, but always use the following Tuesday. The last thing is to use the body of the email to be added to the “Item” column. The two struggles I have is that the date is not working because the script throws an undefined date. Also, in the body of the document, I was trying to strip out my signature. Here is the source of my email:
 

From: Jason Hill <Jason_Hill@redlands.k12.ca.us>
To:
"cabinet-appdTbAjyxDJvxWBg.198a-wtryup7gk7YXPJ9W0.1780@automations.airtableemail.com"
<cabinet-appdTbAjyxDJvxWBg.198a-wtryup7gk7YXPJ9W0.1780@automations.airtableemail.com>
Subject: Test Item
Thread-Topic: Test Item
Thread-Index: AQHbswBR6G8iceaJZkCx50iyRPLykQ==
Date: Mon, 21 Apr 2025 21:00:13 +0000
Message-ID:
<SA1PR18MB4727D4FDCEC7D37C7EC282D998B82@SA1PR18MB4727.namprd18.prod.outlook.com>
Content-Language: en-US
X-MS-Exchange-Organization-ModifySensitivityLabel:
00000000-0000-0000-0000-000000000000;12f3c12c-1919-4500-9b29-c7e9a121c5aa
X-MS-Has-Attach:
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator:
X-MS-Exchange-Organization-RecordReviewCfmType: 0
msip_labels:
MSIP_Label_12f3c12c-1919-4500-9b29-c7e9a121c5aa_Enabled=True;MSIP_Label_12f3c12c-1919-4500-9b29-c7e9a121c5aa_SiteId=bd0085fb-e1ee-4b5a-bdb0-934ea34b064e;MSIP_Label_12f3c12c-1919-4500-9b29-c7e9a121c5aa_SetDate=2025-04-21T21:00:13.477Z;MSIP_Label_12f3c12c-1919-4500-9b29-c7e9a121c5aa_Name=General;MSIP_Label_12f3c12c-1919-4500-9b29-c7e9a121c5aa_ContentBits=0;MSIP_Label_12f3c12c-1919-4500-9b29-c7e9a121c5aa_Method=Standard;
Content-Type: multipart/alternative;
boundary="_000_SA1PR18MB4727D4FDCEC7D37C7EC282D998B82SA1PR18MB4727namp_"
MIME-Version: 1.0

--_000_SA1PR18MB4727D4FDCEC7D37C7EC282D998B82SA1PR18MB4727namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This is a test to see what comes in.


Jason Hill

Deputy Superintendent, Business Services

------------------------------------------------------------

Redlands Unified School District

20 W. Lugonia Ave., Redlands, CA 92373


Phone: 909-307-5300 ext. 20404

Email: jason_hill@redlands.k12.ca.us


Schedule a Meeting<https://fantastical.app/jason_hill/60_minutes>

--_000_SA1PR18MB4727D4FDCEC7D37C7EC282D998B82SA1PR18MB4727namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
This is a test to see what comes in.
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id=3D"Signature" class=3D"elementToProof" style=3D"color: inherit;">
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
color: rgb(247, 150, 70);">
Jason Hill</div>
<div style=3D"font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(2=
55, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif;" dir=3D"=
ltr" id=3D"divtagdefaultwrapper">
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
;">Deputy Superintendent, Business Services</span></p>
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
;">------------------------------------------------------------</span></p>
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
;">Redlands Unified School District</span></p>
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
; color: gray;">20 W. Lugonia Ave., Redlands, CA 92373<br>
<br>
</span></p>
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
; color: rgb(117, 123, 128);">Phone:</span><span style=3D"font-family: Cali=
bri, Helvetica, sans-serif; font-size: 11pt;">&nbsp;</span><span style=3D"f=
ont-family: Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, =
51, 187);"><u>909-307-5300</u></span><span style=3D"font-family: Calibri, H=
elvetica, sans-serif; font-size: 11pt;">&nbsp;ext.
20404</span></p>
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
; color: rgb(117, 123, 128);">Email:
</span><span style=3D"font-family: Calibri, Helvetica, sans-serif; font-siz=
e: 11pt;">jason_hill@redlands.k12.ca.us</span></p>
<div style=3D"background-color: rgb(255, 255, 255); margin: 0px 0in 0.00013=
3333px; font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 3=
3, 33);">
<br>
</div>
<p style=3D"background-color: rgb(255, 255, 255); margin: 0in 0in 0.0001pt;=
font-family: Calibri, sans-serif; font-size: 15px; color: rgb(33, 33, 33);=
">
<span style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt=
;"><a href=3D"https://fantastical.app/jason_hill/60_minutes" title=3D"https=
://fantastical.app/jason_hill/60_minutes" style=3D"margin-top: 0px; margin-=
bottom: 0px;">Schedule a Meeting</a></span></p>
</div>
</div>
</body>
</html>

--_000_SA1PR18MB4727D4FDCEC7D37C7EC282D998B82SA1PR18MB4727namp_--

 


Hmm, when I use the ‘When email received’ trigger, I end up with these:

And so you could just use the Subject, Body and Received in your script?

Sorry, I feel like I’m missing something!


Thanks,  I will keep playing around with it.


Reply