#Sending email after shipment creation with sendgrid

11 messages · Page 1 of 1 (latest)

gloomy snow
#

I am having an issue sending an email with sendgrid after shipment creation. I'm seeing that something is reaching sendgrid with the correct template but the email is being dropped.
I already have emails with order placement and order cancellation working. Is there a bug in the sendgrid plugin for shipment creation? Has anyone got this to work?

glad current
#

I think I am just going to follow all your threads haha. I have the same issue

gloomy snow
#

@glad current I hope someone can help us 🥲 lmk if you get it to work

prime wing
#

Can't you check the details of the drop?

gloomy snow
#

hi @prime wing, it just says "This email could not be sent."

glad current
#

I can't get a single email to be sent using sendgrid for any of the listed events... I tried using subscribers and loaders, but I cannot get it to work. @gloomy snow How did you get order.place or order.canceled to work?

#

I tried using this code for loaders ```import { MedusaContainer, NotificationService } from '@medusajs/medusa';

export default async (container: MedusaContainer): Promise<void> => {
const notificationService = container.resolve<NotificationService>(
'notificationService'
);

notificationService.subscribe('order.placed', 'sendgrid');
notificationService.subscribe('order.canceled', 'sendgrid');
notificationService.subscribe('order.shipment_created', 'sendgrid');
notificationService.subscribe('customer.password_reset', 'sendgrid');
notificationService.subscribe('order.return_requested', 'sendgrid');
notificationService.subscribe('order.refund_created', 'sendgrid');
notificationService.subscribe('order.items_returned', 'sendgrid');
notificationService.subscribe('claim.shipment_created', 'sendgrid');
};

#

this for subscribers ```import {
type SubscriberConfig,
type SubscriberArgs,
OrderService,
} from '@medusajs/medusa';

export default async function handleOrderPlaced({
data,
eventName,
container,
pluginOptions,
}: SubscriberArgs<Record<string, string>>) {
const sendGridService = container.resolve('sendgridService');
const orderService: OrderService = container.resolve('orderService');

const order = await orderService.retrieve(data.id, {
// you can include other relations as well
relations: ['items'],
});

sendGridService.sendEmail({
templateId: 'd-20bd2712f9b9499cb0d0df26aaf839b9',
from: '[email protected]',
to: order.email,
dynamic_template_data: {
// any data necessary for your template...
items: order.items,
status: order.status,
},
});
}

export const config: SubscriberConfig = {
event: OrderService.Events.PLACED,
context: {
subscriberId: 'order-placed-handler',
},
};

#

and my medusa-config.js is { resolve: `medusa-plugin-sendgrid`, options: { api_key: process.env.SENDGRID_API_KEY, from: process.env.SENDGRID_FROM, order_placed_template: process.env.SENDGRID_ORDER_PLACED_ID, order_canceled_template: process.env.SENDGRID_ORDER_CANCELED_ID, order_shipped_template: process.env.SENDGRID_ORDER_SHIPPED_ID, order_return_requested_template: process.env.SENDGRID_ORDER_RETURN_REQUESTED_ID, order_items_returned_template: process.env.SENDGRID_ORDER_ITEMS_RETURNED_ID, customer_password_reset_template: process.env.SENDGRID_CUSTOMER_PASSWORD_RECOVERY_ID, user_password_reset_template: process.env.SENDGRID_USER_PASSWORD_RECOVERY_ID, medusa_restock_template: process.env.SENDGRID_RESTOCK_NEEDED_ID, }, },

#

In sendgrid I have a verified single sender, and have created the dynamic templates, and passed the IDs starting with d-xxxx to the .env

#

I think I have a problem connecting to sendgrid... as whatever I do on the storefront, nothing seems to be logged on sendgrid