首页 > 解决方案 > 如何使用 nodemailer nodejs 发送日历邀请?

问题描述

我正在使用 Nodemailer 发送日历邀请。我面临一个问题,即这会向我发送“invite.ics”文件而不是发送日历邀请。电子邮件发送成功,但它发送“invite.ics”文件。谁能帮我找出问题出在哪里以及如何解决这个问题?提前致谢。

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()
            }
        });

        });

标签: node.jsexpressgoogle-apiicalendarnodemailer

解决方案


推荐阅读