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
Every hour, the mail in your Gmail account carrying a label you choose is collected and turned into pages in a Notion database, one page per message. The subject becomes the page title, and the page holds who sent it, when it was sent, a link that opens the original in Gmail, and the message body.
Once a page exists, the message picks up a second label, 'Filed to Notion', and the search that finds work deliberately leaves out anything carrying it, so a message is never filed twice however often the workflow runs. Everything goes into the page content rather than database columns, so it works with any database whatever its columns are called; the only column written is the title. A message that cannot be read or filed keeps its label, is reported in the run, and is tried again on the next sweep. Long messages are shortened to fit Notion's limit on a block of text.
You need a Gmail label to watch and a Notion database shared with your Notion integration.
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 labelExistsdoneLabel.Create label doneLabel.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 fileErroremail.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 emptypageTitle to (no subject).Change pageTitle to (no subject).sender is emptyIf sender is emptysender to (unknown sender).Change sender to (unknown sender).bodyText is emptyIf bodyText is emptybodyText to (no message body).Change bodyText to (no message body).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 dateErrormessageId. 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 emptysentAt to dateHeader.Change sentAt to dateHeader.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 labelErrordoneLabel to email messageId.Add label doneLabel to email messageId.filedCount.Add 1 to filedCount.sender into Notion.Show in the output: Filed '@pageTitle' from sender into Notion.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.