I am sending a calendar invitation using Nodemailer. I am facing an issue that this sends me an "invite.ics" file instead for a send calendar invitation. Email sends successfully but it sends the "invite.ics" file. Can anybody help me to find out where is the issue and how can I fix this issue? Thanks in advance.
const ical = require('ical-generator');
const cal = ical();
const transporter = nodemailer.createTransport({
service: "Gmail",
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: 'vsvishnusingh@gmail.com',
pass: 'mypassword',
}
});
return new Promise(function(resolve,reject){
var options = {
start: moment(),
end: moment().add(1, 'hour'),
timestamp: moment(),
summary: 'My Event',
title : 'Annual function',
description : 'Lets enjoy and relax',
id : 'wdcwe76234e127eugb',
organiser : {'name' : 'Vishnu Singh', 'email':'vsvishnusingh@gmail.com'},
location : 'School'
}
cal.createEvent({
start: new Date(options.start),
end: new Date(options.end),
summary: options.summary || options.subject,
description: options.description || "",
location: options.location,
organizer: {
name: options.organiser.name,
email: options.organiser.email
},
method: 'REQUEST'
});
var mailObj = {
from: "vsvishnusingh@gmail.com",
to: "vishnutest@gmail.com",
subject: "Your Subject",
text: "Some text in the body",
alternatives: [{
contentType: 'text/calendar; charset=UTF-8; method=REQUEST',
content: new Buffer(cal.toString())
}]
};
transporter.sendMail(mailObj, function(err, info){
console.log(err,info);
if (err) {
console.log("Error while sending email ...", err)
reject(err)
} else {
console.log("Email send successfully!");
resolve()
}
});
});