26 lines
1 KiB
TypeScript
26 lines
1 KiB
TypeScript
|
// import { config } from "dotenv";
|
||
|
// import { User, Order } from "../mongoose/Schema";
|
||
|
// import client from '@sendgrid/mail';
|
||
|
// config();
|
||
|
|
||
|
// export async function sendEmailasync(orderId:string, userId: string) {
|
||
|
// console.log(`Sending email for order ${orderId} to user ${userId}`);
|
||
|
// try {
|
||
|
// client.setApiKey(process.env.SENDGRID_API_KEY);
|
||
|
// const msg = {
|
||
|
// to: await User.findOne({ _id: userId }).select('email'),
|
||
|
// from: process.env.EMAIL_FROM,
|
||
|
// subject: 'Order Confirmation',
|
||
|
// text: 'Your order has been placed',
|
||
|
// html: '<strong>Thank you for shopping with us!</strong>'
|
||
|
// };
|
||
|
// await client.send(msg);
|
||
|
// console.log(`Email sent for order ${orderId} to user ${userId}`);
|
||
|
// // Update the order to indicate email has been sent
|
||
|
// await Order.findOne({ _id: orderId }).updateOne({ emailSent: true });
|
||
|
// console.log(`Updated order ${orderId} to indicate email has been sent`);
|
||
|
// return;
|
||
|
// } catch (error) {
|
||
|
// console.error('Error sending email:', error);
|
||
|
// }
|
||
|
// };
|