错误:未定义传输方法

时间:2016-07-09 08:40:07

标签: javascript node.js express

我需要从我的应用程序创建一个outlook日历事件,我正在使用快速js但是我收到一个错误,因为[错误:没有定义传输方法] 并且在一段时间后,响应在一些1189989毫秒之后成功了200次

但是在展望中,我无法看到任何事件

所以这就是我试过的

  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();
var icsFileContent = builder.toString();
var smtpOptions = {
"secureConnection": true,
"from": "*****",
"host": "smtp-mail.outlook.com",
"secureConnection": true,
"port": 587,
"transportMethod": "SMTP",
"auth": {
    user: '******',
    pass: '*****'
}};
var builder = icalToolkit.createIcsFileBuilder();
builder.events.push({ 
 start: new Date(),
 end: new Date(),
  });
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);
    }
});};

这是路由完成的index.js

'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;

我不明白我哪里出错了

任何帮助都将受到高度赞赏..

1 个答案:

答案 0 :(得分:1)

您已将transportMethod添加到smtpOptions中,如下所示:

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport(
{
        from: "no-reply@example.com",
        host: "smtp.mail.com",
        secureConnection: true,
        port: 465,
        transportMethod: "SMTP",
        auth: {
            user: "mail.user@mail.com",
            pass: "userpass"
        }
    }
));

transporter.sendMail({
            from: "email from",
            to: data.to,
            subject: "test",
            html: "test email"
});

如果您有域名,则可以注册MailGun帐户。否则,您可以使用Gmail SMTP