DEV Community

Cover image for How to send upsell emails with MedusaJS and Postmark
Bram Hammer
Bram Hammer

Posted on

How to send upsell emails with MedusaJS and Postmark

For example someone buys a few samples at your store and you never hear from him again.. That's frustrating!

We all know that follow-up/upsell mails help to keep your customers engaged and make sure they won't forget you. I want to explain how you can easily send those emails with MedusaJS.

Install the plugin

npm i medusa-plugin-postmark
Enter fullscreen mode Exit fullscreen mode

Postmark template

Not sure where to start with the template? A small explaination can be found here or you can use the sourcecode of a stripo mail template.

If you created your template (and saved) you need to copy the ID that can be found in the top right corner while editing your template.

Postmark template

Setup your medusa config

Open your medusa-config.js and add the following lines in the plugin array.

{
        resolve: `medusa-plugin-postmark`,
        options: {
            server_api: process.env.POSTMARK_SERVER_API,
            from: process.env.POSTMARK_FROM,
            bcc: process.env.POSTMARK_BCC || null,
            pdf: {
                enabled: false
            },
            events: {
            },
            upsell: {
                enabled: process.env.POSTMARK_UPSELL_ENABLED || false,
                template: process.env.POSTMARK_UPSELL_TEMPLATE || null,
                delay: process.env.POSTMARK_UPSELL_DELAY || 9, // delay in days
                valid: process.env.POSTMARK_UPSELL_VALID || 30, // delay in days
                collection: process.env.POSTMARK_UPSELL_COLLECTION || null,
            },
            default_data: {
                product_url: process.env.POSTMARK_PRODUCT_URL || '',
                product_name: process.env.POSTMARK_PRODUCT_NAME || '',
                company_name: process.env.POSTMARK_COMPANY_NAME || '',
                company_address: process.env.POSTMARK_COMPANY_ADDRESS || '',
            }
        }
    },
Enter fullscreen mode Exit fullscreen mode

and make sure you have the following .env keys and values

POSTMARK_SERVER_API=4e7bc01b-****-****-****-51f8b224c6c8
POSTMARK_FROM=your@mail.com
POSTMARK_PRODUCT_URL=https://mail.com/
POSTMARK_PRODUCT_NAME=
POSTMARK_COMPANY_NAME=
POSTMARK_COMPANY_ADDRESS=
POSTMARK_UPSELL_DELAY=7
POSTMARK_UPSELL_ENABLED=true
POSTMARK_UPSELL_TEMPLATE=123456
POSTMARK_UPSELL_COLLECTION=pcol_01GQDXMFP78WHSFFAHB6K4EV79
POSTMARK_UPSELL_VALID=21
Enter fullscreen mode Exit fullscreen mode

Make sure you set the correct values, and change the POSTMARK_UPSELL_TEMPLATE for the correct template ID in postmark and add your own collection to only mail people who bought in that collection.

The POSTMARK_FROM email address must be a verified sender in your Postmark account.

You're ready to go!

You're ready to remind your customers how bad they need your products!
Keep in mind! If you install this on a running website it could mail old orders. Want to prevent that? Make sure every order has the following metadata ( or add it to existing metadata)

{
    "upsell_sent": true
}
Enter fullscreen mode Exit fullscreen mode

Having problems?

Experiencing issues, or need a little help? Let me know in the comments and I will try to help when possible!

Top comments (0)