Pushing Podio
Search
📮

Email to Notion

Getting things into Notion using email is an often requested feature that doesn’t exist natively. However, if you have ProcFu, you can leverage the new ProcScript code engine to get the job done.

The Notion Inbox

Most Notion users have an “Inbox” page. An easily-accessible page that is a dumping ground for information.

If you have an idea or come across something worth noting, you dump it into the Inbox page. Then when you have more time, you can go through the Inbox items and move them to their appropriate place.

Take note of the URL of this page as we’re going to write a quick script to publish emails to it.

The ProcFu (ProcScript) Code

Go to the ProcScript Playground in ProcFu, and create a new script (NOT legacy code blocks).

Give it a name and click "save".

Then, for "Mode", select "Email - from email". This will then give you the unique email address for triggering this piece of code.

Take note of this email address. This address is where you'll be sending or forwarding email to later.

Back to the code …

The first thing we’ll want to do is set any variables, which in this case is the URL of the inbox page from earlier.

inbox = "https://www.notion.so/globi/Inbox-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

Replace this with your own page ID.

The payload of any email, will be available in a variable called payload. To see the structure, you can simply send an email to your new address, and refresh the page - the last payload will be in the console.

We’ll start by creating a toggle block with the subject of the email as it’s content.

subject = payload["POST"]["headers"]["subject"]
if ( subject == NULL ) subject = "unknown"
blockId = notion_block_create("toggle", subject, inbox)

Then we’ll create a text sub-block to the toggle with the text body of the email.

body = trim(payload["POST"]["text"])
// if no text is present, use the html part
if ( body == NULL ) {
	body = trim(strip_tags_gf(payload["POST"]["html"]))
}
if ( body == NULL ) {
	body = ""
}
bodyId = notion_block_create("text", body, blockId)

For bonus points, we’ll take any attachments and add them inside the toggle as well.

if ( payload["FILES"] ) {
    foreach ( payload["FILES"] as file ) {
        json = json_encode(file)
        fileBlockId = notion_block_add_file(blockId, json)
    }
}

That’s it. Not a huge amount of code now, is it? This is the entire code block:

// email_to_notion_inbox
// send email to script address and it will create a new item in the Notion Inbox page
// will create new toggle with subject of email, and inner text with content and any attachments

// vars
inbox = "https://www.notion.so/globi/Inbox-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

// create toggle
subject = payload["POST"]["headers"]["subject"]
if ( subject == NULL ) subject = "unknown"
blockId = notion_block_create("toggle", subject, inbox)

// create body as text inside toggle
body = trim(payload["POST"]["text"])
// if no text is present, use the html part
if ( body == NULL ) {
	body = trim(strip_tags_gf(payload["POST"]["html"]))
}
if ( body == NULL ) {
	body = ""
}
bodyId = notion_block_create("text", body, blockId)

// attach any files
if ( payload["FILES"] ) {
    foreach ( payload["FILES"] as file ) {
        json = json_encode(file)
        fileBlockId = notion_block_add_file(blockId, json)
    }
}

The Result

Now you can send an email into Notion very easily.

Compose an email to your script's email address with subject, body, and optional attachments:

And it will appear in your Notion Inbox within seconds:

(c) 2022 Globi Web Solutions | Join the Discussion in our Podio Workspace.