Turns mail carrying a Gmail label you choose into pages in a Notion database, and never files the same message twice.

UsesGmailNotion

File labeled 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.

Run every hour.Run every hour.
Set gmailLabel to blank.Set gmailLabel to blank.
Set notionDatabaseId to blank.Set notionDatabaseId to blank.
Set filedLabel to “Filed to Notion”.Set filedLabel to “Filed to Notion”.
Set titleProperty to “Name”.Set titleProperty to “Name”.
Set maxEmails to 25.Set maxEmails to 25.
Trim gmailLabel and save it as watchLabel.Trim gmailLabel and save it as watchLabel.
Trim filedLabel and save it as doneLabel.Trim filedLabel and save it as doneLabel.
Trim notionDatabaseId and save it as databaseId.Trim notionDatabaseId and save it as databaseId.
Trim titleProperty and save it as titleColumn.Trim titleProperty and save it as titleColumn.
If a step below fails, save the error as labelExistsIf a step below fails, save the error as labelExists
Try
GmailGmailCreate label doneLabel.Create label doneLabel.
On error
Show in the output: Using the existing '@doneLabel' label in Gmail.Show in the output: Using the existing '@doneLabel' label in Gmail.
Set searchQuery to “label:“@watchLabel” -label:“@doneLabel””.Set searchQuery to “label:“@watchLabel” -label:“@doneLabel””.
GmailGmailList emails matching searchQuery. Save it as found.List emails matching searchQuery. Save it as found.
Set messages to found.emails.Set messages to found.emails.
Set filedCount to 0.Set filedCount to 0.
For each email in messages:For each email in messages:
If a step below fails, save the error as fileErrorIf a step below fails, save the error as fileError
Try
Trim email.id and save it as messageId.Trim email.id and save it as messageId.
Shorten email.subject to 200 characters and save it as subject.Shorten email.subject to 200 characters and save it as subject.
Trim email.from and save it as sender.Trim email.from and save it as sender.
Shorten email.body to 1800 characters and save it as bodyText.Shorten email.body to 1800 characters and save it as bodyText.
Set pageTitle to subject.Set pageTitle to subject.
If pageTitle is emptyIf pageTitle is empty
Yes
Change pageTitle to “(no subject)”.Change pageTitle to “(no subject)”.
No
No steps
If sender is emptyIf sender is empty
Yes
Change sender to “(unknown sender)”.Change sender to “(unknown sender)”.
No
No steps
If bodyText is emptyIf bodyText is empty
Yes
Change bodyText to “(no message body)”.Change bodyText to “(no message body)”.
No
No steps
Set messageLink to “https://mail.google.com/mail/u/0/#all/@messageId”.Set messageLink to “https://mail.google.com/mail/u/0/#all/@messageId”.
Set sentAt to “(date not available)”.Set sentAt to “(date not available)”.
If a step below fails, save the error as dateErrorIf a step below fails, save the error as dateError
Try
GmailGmailGet the sender, subject and date of email messageId. Save it as headers.Get the sender, subject and date of email messageId. Save it as headers.
Trim headers.Date and save it as dateHeader.Trim headers.Date and save it as dateHeader.
If dateHeader isn't emptyIf dateHeader isn't empty
Yes
Change sentAt to dateHeader.Change sentAt to dateHeader.
No
No steps
On error
Show in the output: Could not read the sent date for message messageId; filing it without one.Show in the output: Could not read the sent date for message messageId; filing it without one.
Set summary to From: senderSet summary to From: sender Sent: sentAt Gmail label: watchLabel.
NotionNotionCreate the page pageTitle in databaseId.Create the page pageTitle in databaseId. Title column: titleColumn
If a step below fails, save the error as labelErrorIf a step below fails, save the error as labelError
Try
GmailGmailAdd label doneLabel to email messageId.Add label doneLabel to email messageId.
On error
Show in the output: Filed '@pageTitle' into Notion but could not add the '@doneLabel' label to the message, so it may be filed a second time on the next run.Show in the output: Filed '@pageTitle' into Notion but could not add the '@doneLabel' label to the message, so it may be filed a second time on the next run.
Add 1 to filedCount.Add 1 to filedCount.
Show in the output: Filed '@pageTitle' from sender into Notion.Show in the output: Filed '@pageTitle' from sender into Notion.
On error
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.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.
Show in the output: 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.