Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

code review

ThieryMichel272845907a36
diff --git a/doc/src/content/docs/developers/deploy.mdx b/doc/src/content/docs/developers/deploy.mdx
index 61119169..54ffb554 100644
--- a/doc/src/content/docs/developers/deploy.mdx
+++ b/doc/src/content/docs/developers/deploy.mdx
@@ -71,6 +71,7 @@ SB_PUBLISHABLE_KEY: Your supabase project publishable key
POSTMARK_WEBHOOK_USER: User configured in Postmark to secure the webhook
POSTMARK_WEBHOOK_PASSWORD: Password configured in Postmark to secure the webhook
POSTMARK_WEBHOOK_AUTHORIZED_IPS: List of IPs (comma separated) authorized to send requests to the Postmark webhook
+POSTMARK_INBOUND_EMAIL: The email address configured in Postmark to receive inbound emails
```
> **Note:** The `POSTMARK_*` variables are required for Atomic CRM's inbound email features. Have a look at the the [inbound email configuration](../inbound-email-configuration) to learn more about their usage and setup.
diff --git a/doc/src/content/docs/developers/inbound-email-configuration.mdx b/doc/src/content/docs/developers/inbound-email-configuration.mdx
index 7fe5bc4e..aafa398b 100644
--- a/doc/src/content/docs/developers/inbound-email-configuration.mdx
+++ b/doc/src/content/docs/developers/inbound-email-configuration.mdx
@@ -37,6 +37,7 @@ In a terminal, after [linking your Supabase project](../supabase-configuration#a
npx supabase secrets set POSTMARK_WEBHOOK_USER=<user>
npx supabase secrets set POSTMARK_WEBHOOK_PASSWORD=<password>
npx supabase secrets set POSTMARK_WEBHOOK_AUTHORIZED_IPS=<comma-separated list of IPs>
+npx supabase secrets set POSTMARK_INBOUND_EMAIL=<your-postmark-inbound-email> # Optional, only needed if you want to to be able to transfer mail directly to the CRM
```
These commands will push the secrets to your remote Supabase project.
@@ -49,6 +50,7 @@ If you are using this repository's GitHub Actions to automatically deploy to you
POSTMARK_WEBHOOK_USER=<user>
POSTMARK_WEBHOOK_PASSWORD=<password>
POSTMARK_WEBHOOK_AUTHORIZED_IPS=<comma-separated list of IPs>
+POSTMARK_INBOUND_EMAIL=<your-postmark-inbound-email> # Optional, only needed if you want to to be able to transfer mail directly to the CRM
```
## Application Configuration
diff --git a/doc/src/content/docs/users/inbound-email.mdx b/doc/src/content/docs/users/inbound-email.mdx
index 33524393..ca1450f6 100644
--- a/doc/src/content/docs/users/inbound-email.mdx
+++ b/doc/src/content/docs/users/inbound-email.mdx
@@ -15,10 +15,13 @@ Send of forward emails to Atomic CRM's inbound email address to automatically ad
![Inbound Email Address](../../images/inbound-email.jpg)
-When you write to a contact in your email client, add the inbound email address in the **Bcc** field. PPostmark will receive a copy of your email, and forward it to Atomic CRM. Atomic CRM uses the sender's email address to identify the user, and the recipient's email address to identify the contact. If the contact does not yet exist, Atomic CRM creates it using the email's domain as company name. The content of the email is added as a note to the contact.
+When you write to a contact in your email client, add the inbound email address in the **Bcc** field. Postmark will receive a copy of your email, and forward it to Atomic CRM. Atomic CRM uses the sender's email address to identify the user, and the recipient's email address to identify the contact. If the contact does not yet exist, Atomic CRM creates it using the email's domain as company name. The content of the email is added as a note to the contact.
**Tip**: Use the **Bcc** field to send emails to Atomic CRM without notifying the recipients.
+You can also forward existing emails to the inbound email address to add them as notes to the corresponding contacts.
+Atomic CRM will extract the original sender and recipient from the email content to identify the contact and user.
+
## Example
Consider the following email:
@@ -46,3 +49,32 @@ Meeting with Kim Hegmann
Hi Kim,
I would like to schedule a meeting with you next week. Please let me know your availability.
```
+
+Consider another email that you forward to the inbound email address directly:
+
+```txt
+From: Jane Doe <[email protected]>
+Subject: Fwd: I will not be able to attend the meeting
+
+---------- Forwarded message ----------
+From: Kim Hegmann <[email protected]>
+To: Jane Doe <[email protected]>
+Subject: I will not be able to attend the meeting
+
+Hi Jane,
+I am sorry but I will not be able to attend the meeting we scheduled.
+Can we reschedule it for the week after?
+```
+
+When receiving this email, Atomic CRM will:
+- Identify the _Kim Hegmann_ contact based on the original sender's email address
+- Add a note to the _Kim Hegmann_ contact with the following content:
+
+```txt
+I will not be able to attend the meeting
+
+Hi Jane,
+I am sorry but I will not be able to attend the meeting we scheduled.
+Can we reschedule it for the week after?
+```
diff --git a/supabase/functions/postmark/index.ts b/supabase/functions/postmark/index.ts
index b6403f6e..a5240ed2 100644
--- a/supabase/functions/postmark/index.ts
+++ b/supabase/functions/postmark/index.ts
@@ -56,9 +56,10 @@ Deno.serve(async (req) => {
const salesEmails =
allSales.data?.map((s: { email: string }) => s.email) ?? [];
- // If the email is sent to the inbound email address, and the sender is a known sales email,
+ // If we have an INBOUND_EMAIL and the email is sent to the inbound email address, and the sender is a known sales email,
// then we can try to extract the real recipient email from the body of the email
if (
+ INBOUND_EMAIL &&
ToFull.length === 1 &&
ToFull[0].Email === INBOUND_EMAIL &&
salesEmails.includes(FromFull.Email)
@@ -81,7 +82,7 @@ Deno.serve(async (req) => {
// Return a 403 to let Postmark know that it's no use to retry this request
// https://postmarkapp.com/developer/webhooks/inbound-webhook#errors-and-retries
return new Response(
- `Could not extract recipient email from transferred email body: ${TextBody}`,
+ `Could not extract recipient email from transferred email body.`,
{ status: 403 },
);
}
@@ -257,4 +258,60 @@ const checkBody = (json: any) => {
}
]
}'
+ To trigger the email forwarding feature, you can change the "To" and "ToFull" fields to have the INBOUND_EMAIL, and add an email address that is neither a sales nor the INBOUND_EMAIL, for example:
+ curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/postmark' \
+ --header 'Content-Type: application/json' \
+ --header 'Authorization: Basic dGVzdHVzZXI6dGVzdHB3ZA==' \
+ --data '{
+ "FromName": "Postmarkapp Support",
+ "MessageStream": "inbound",
+ "From": "[email protected]",
+ "FromFull": {
+ "Email": "[email protected]",
+ "Name": "Postmarkapp Support",
+ "MailboxHash": ""
+ },
+ "ToFull": [
+ {
+ "Email": "[email protected]",
+ "Name": "",
+ "MailboxHash": ""
+ }
+ ],
+ "Cc": "",
+ "CcFull": [],
+ "Bcc": "",
+ "BccFull": [],
+ "OriginalRecipient": "[email protected]",
+ "Subject": "Fwd: Test for forwarding mail",
+ "MessageID": "32dcbecb-57d0-476e-9591-c747808cb599",
+ "ReplyTo": "",
+ "MailboxHash": "",
+ "Date": "Thu, 5 Mar 2026 10:41:26 +0100",
+ "TextBody": "---------- Forwarded message ---------\nFrom : Postmarkapp Support <[email protected]>\nDate: Fri, 1 Aug 2014 16:45:32 -04:00\nSubject: Test for forwarding mail\nTo: Postmarkapp Support <[email protected]>\n\n\nThe transferred message body\n",
+ "HtmlBody": "<div dir=\"ltr\"><br><br><div class=\"gmail_quote gmail_quote_container\"><div dir=\"ltr\" class=\"gmail_attr\">---------- Forwarded message ---------<br>From: <strong class=\"gmail_sendername\" dir=\"auto\">Postmarkapp Support</strong> <span dir=\"auto\">&lt;<a href=\"mailto:[email protected]\">[email protected]</a>&gt;</span><br>Date: Fri, 1 Aug 2014 16:45:32 -04:00<br>Subject: Test for forwarding mail<br>To: Postmarkapp Support &lt;<a href=\"mailto:[email protected]\">[email protected]</a>&gt;<br></div><br><br><div dir=\"ltr\">The transferred message body</div>\n</div></div>\n",
+ "StrippedTextReply": "",
+ "Tag": "",
+ "Headers": [
+ {
+ "Name": "X-Header-Test",
+ "Value": ""
+ },
+ {
+ "Name": "X-Spam-Status",
+ "Value": "No"
+ },
+ {
+ "Name": "X-Spam-Score",
+ "Value": "-0.1"
+ },
+ {
+ "Name": "X-Spam-Tests",
+ "Value": "DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_PASS"
+ }
+ ],
+ "Attachments": []
+ }'
+
*/