This question is already asked here but no answer, how to add outlook event using nodejs
I am using ics and Nodemailer to send events to the clients using emails.
I am getting correct results on the gmail as expected
But it is not working on the outlook, it just appears as the attachment and not added to the outlook calendar and says cannot import ics file.
I have searched the internet and the chatgpt but unable to find any solution.
In short, I want to send calender events using Nodejs to the outlook and gmail. Right now I am using ics library to create ics file and sends it using nodemailer
MY ICS FILE
This is how I am sending,
const organizerMailOptions: MailOptions = {
from: organizer.email,
to: organizer.email,
subject: `Event Created: ${title}`,
html: organizerEventBodyTemplate(event),
attachments: [
{
filename: "invite.ics",
content: createdEvent as string,
contentType: "text/calendar",
},
],
};
I am trying to add calendar events to the outlook and gmail via email.
FOUND THE SOLUTION MYSELF It was a problem with the nodemailer attachment.
Just convert attachments to icalEvent and it will work fine.
Updated nodemailer part,
const attendeesMailOptions: MailOptions = {
from: organizer.email,
to: [...attendees.map((attendee) => attendee.email)],
subject: title,
html: attendeeEventBodyTemplate(event, organizer),
icalEvent: {
filename: "invite.ics",
method: "request",
content: createdEvent as string,
},
};