Turns mail carrying a Gmail label you choose into pages in a Notion database, and never files the same message twice.
Uses
GmailNotion
File labelled email into a Notion database
gmailLabel to blank.Set gmailLabel to blank.notionDatabaseId to blank.Set notionDatabaseId to blank.filedLabel to Filed to Notion.Set filedLabel to Filed to Notion.titleProperty to Name.Set titleProperty to Name.maxEmails to 25.Set maxEmails to 25.gmailLabel and save it as watchLabel.Trim gmailLabel and save it as watchLabel.filedLabel and save it as doneLabel.Trim filedLabel and save it as doneLabel.notionDatabaseId and save it as databaseId.Trim notionDatabaseId and save it as databaseId.titleProperty and save it as titleColumn.Trim titleProperty and save it as titleColumn.labelExistsIf a step below fails, save the error as labelExistsTry
doneLabel.Create label doneLabel.On error
searchQuery to label:@watchLabel -label:@doneLabel.Set searchQuery to label:@watchLabel -label:@doneLabel.searchQuery. Save it as found.List emails matching searchQuery. Save it as found.messages to found.emails.Set messages to found.emails.filedCount to 0.Set filedCount to 0.email in messages:For each email in messages:fileErrorIf a step below fails, save the error as fileErrorTry
email.id and save it as messageId.Trim email.id and save it as messageId.email.subject to 200 characters and save it as subject.Shorten email.subject to 200 characters and save it as subject.email.from and save it as sender.Trim email.from and save it as sender.email.body to 1800 characters and save it as bodyText.Shorten email.body to 1800 characters and save it as bodyText.pageTitle to subject.Set pageTitle to subject.pageTitle is emptyIf pageTitle is emptyYes
pageTitle to (no subject).Change pageTitle to (no subject).No
No steps
sender is emptyIf sender is emptyYes
sender to (unknown sender).Change sender to (unknown sender).No
No steps
bodyText is emptyIf bodyText is emptyYes
bodyText to (no message body).Change bodyText to (no message body).No
No steps
messageLink to https://mail.google.com/mail/u/0/#all/@messageId.Set messageLink to https://mail.google.com/mail/u/0/#all/@messageId.sentAt to (date not available).Set sentAt to (date not available).dateErrorIf a step below fails, save the error as dateErrorTry
messageId. Save it as headers.Get the sender, subject and date of email messageId. Save it as headers.headers.Date and save it as dateHeader.Trim headers.Date and save it as dateHeader.dateHeader isn't emptyIf dateHeader isn't emptyYes
sentAt to dateHeader.Change sentAt to dateHeader.No
No steps
On error
messageId; filing it without one.Show in the output: Could not read the sent date for message messageId; filing it without one.summary to From: senderSet summary to From: sender
Sent: sentAt
Gmail label: watchLabel.pageTitle in databaseId.Create the page pageTitle in databaseId.labelErrorIf a step below fails, save the error as labelErrorTry
doneLabel to email messageId.Add label doneLabel to email messageId.On error
filedCount.Add 1 to filedCount.sender into Notion.Show in the output: Filed '@pageTitle' from sender into Notion.On error
email.id as text - it keeps its label and will be picked up on the next run. Reason: fileError as text.Show in the output: Could not file message email.id as text - it keeps its label and will be picked up on the next run. Reason: fileError as text.filedCount as text message(s) filed into Notion from the '@watchLabel' Gmail label.Show in the output: filedCount as text message(s) filed into Notion from the '@watchLabel' Gmail label.