In your scenario, you can use Vercel's Cron Jobs feature to schedule the email sending task. Cron jobs are time-based scheduling tools used to automate repetitive tasks. By using a specific syntax called a cron expression, you can define the frequency and timing of each task. This helps improve efficiency and ensures that important processes are performed consistently source (https://vercel.com/docs/cron-jobs).
To send emails from within your application, you can use Serverless Functions. You can either rely on the outgoing SMTP connection of your Serverless Function or use the API of an external service. Vercel recommends the use of third-party mail services like Postmark, Resend, SendGrid, AWS SES, and MailChimp source (https://vercel.com/guides/sending-emails-from-an-application-on-vercel).
Here's an example of how you can set up a cron job for a dynamic route in your vercel.json:
{
"crons": [
{
"path": "/api/send-emails",
"schedule": "0 5 * * *"
}
]
}
In this example, the cron job will trigger the /api/send-emails route at 5 AM every day. You can adjust the schedule according to your needs.
In your serverless function at /api/send-emails, you can implement the logic to fetch the followers of the seller and send them an email about the new product. Here's a simplified example:
export async function POST(req: Request) {
const followers = await getFollowers();
const product = await getNewProduct();