Nodemailer send calendar event and add it to googl

2019-07-13 20:04发布

问题:

I am trying to send a calendar event to Gmail account using nodemailer. Here is my code

let transporter = nodemailer.createTransport({
                host: 'smtp.gmail.com',
                port: 587,
                secure: false,
                auth: {
                    type: 'OAuth2',
                    user: 'xxx',
                    accessToken: accessToken
                }
            })
            transporter.sendMail(createGmailCalenderEVent(options), (err, info) => {
                return err ? reject(err) : resolve(info);
            })


 createGmailCalenderEVent: (options) => {
        let cal = ical();
        cal.addEvent({
            start: new Date(options.start),
            end: new Date(options.end),
            summary: options.summary || options.subject,
            description: options.description || "",
            location: options.location
        });
        return {
            from: options.from,
            to: options.to.required,
            subject: options.subject,
            html: options.html,
            alternatives: [{
                contentType: "text/calendar",
                content: new Buffer(cal.toString())
            }]
        }
    }

It is working fine. But instead of adding event direclty to the calendar. It is giving the option to a user to add the event to the calendar. So Is it possible to directly add the event to Google calendar of a sender using nodemailer?