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;
// 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);
Page 1 / 1
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