#Sendgrid Notification on Customer creation

9 messages · Page 1 of 1 (latest)

sudden mango
#

Hi! I want to send an email to the customers that register for the first time. I figured it shouldn't be too hard since Medusa already offers the event customer.created (https://docs.medusajs.com/development/events/events-list#customer-events)

So I wanted to ask if my plan is correct:

  • create a new subscribe that listens to the event customer.created in the /src/subscribers directory of the backend repo.
  • send email via the sendgrid plugin when the event is triggered

It made sense to me, so I went and created this class in /src/subscribers/customerCreatedNotifier.ts

import { Customer } from "@medusajs/medusa"

/**
 * https://docs.medusajs.com/development/events/events-list#customer-events
 * customer.created event
 */
class CustomerCreatedNotifierSubscriber {
    constructor({ eventBusService }) {
        eventBusService.subscribe("customer.created", this.handleCustomerCreated)
    }

    handleCustomerCreated = async (customerData: Customer) => {
        //TODO: send email via sendgrid plugin
    }
}

export default CustomerCreatedNotifierSubscriber;

But now I'm stuck... I can't really figure out how to send the mail using the sendgrid plugin, since there is very little documentation on it (https://www.npmjs.com/package/medusa-plugin-sendgrid)

Does someone know how to do it? Thanks in advance!

Learn about the available events and their data payloads in Medusa. Events can be used to perform an action when the events are triggered.

white sun
#

Hello, I think the sendgrid plugin currently does not handle customer.created event

But it should be very easy to implement. You'll have to add some lines to the /src/services/sendgrid.js
and create subscriber for it.

Check out this plugin which includes customer.created for reference -
https://github.com/Hemann55/medusa-plugin-mailjet

You can submit a PR once you implement 🙂

GitHub

Mailjet Plugin for Medusa to send transactional emails. - GitHub - Hemann55/medusa-plugin-mailjet: Mailjet Plugin for Medusa to send transactional emails.

tall ledge
sudden mango
#

Ah very nice! didnt know how I could access the sendgridService

#

But i mean there isn’t really a reason why it’s not directly implemented in the SendGrid Plug-in or is there? Cause then everyone using the plug-in could just use it without adding their own subscriber

tall ledge
#

You can make a PR 🙂

sudden mango
#

Would you say it's a Bug report (I need to choose it for a new issue on github...) Cause Feature request just opens a github discussion