shikha shikha - 4 months ago
381 0

I need to create an outlook calender event from my application where i am using express js but i am getting an error as [Error:No transport method defined] and after sometime the responde is 200 success after some 1189989 ms

But in outlook i couldn't able to see any event

so here is what i tried

Node.js

Error:No transport method defined

'use strict';

var _ = require('lodash');
var Outlook = require('./outlook.model');
var icalToolkit = require('ical-toolkit');
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

//Create a iCal object
var builder = icalToolkit.createIcsFileBuilder();
builder.method = 'REQUEST';
builder.events.push({
 
  //Event start time, Required: type Date() 
  start: new Date(),
  
  //Event end time, Required: type Date() 
  end: new Date(),
  });
//builder.method = meeting.method;
//Add the event data

var icsFileContent = builder.toString();
var smtpOptions = {
    "secureConnection": true,
    "from": "******",
    "host": "smtp-mail.outlook.com",
    "secureConnection": true,
    "port": 587,
    "transportMethod": "SMTP",
    "auth": {
        user: '******',
        pass: '*****'
    }
};

var transporter = nodemailer.createTransport(smtpTransport(smtpOptions));

var mailOptions = {
    from: '*****',
    to: '*******',
    subject: 'Meeting to attend',
    html: "Anything here",

    text: "hiiiiiiiiiiiiiiiiii",
    alternatives: [{
        contentType: 'text/calendar; charset="utf-8"; method=REQUEST',
        content: icsFileContent.toString()
    }]
};

//send mail with defined transport object 
exports.send = function(req, res) {
    transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
            console.log(error);
        } else {
            console.log('Message sent: ' + info.response);
        }
    });
};



'use strict';

var express = require('express');
var controller = require('./outlook.controller');

var router = express.Router();

router.get('/', controller.index);
router.get('/send', controller.send);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);

module.exports = router;