0

我需要设置一个 Outlook 日历事件,为此我使用邮戳 SMTP 服务我使用 iCalToolkit 创建日历对象。

但在这里我收到一个错误 [未定义传输方法] 几天前它可以正常工作,但它今天开始显示错误。我正在使用 express 框架我不明白这个问题

    var _ = require('lodash');
var Outlook = require('./outlook.model');

exports.sendMsg = function(req, res) {
    console.log("this is outlook ctrl" + req.query.dateOfInterview);
    var icalToolkit = require('ical-toolkit');
    var postmark = require("postmark");

    // Example request
    var client = new postmark.Client("key");
    //var postmark = require('postmark');
    //var client = new postmark.Client('xxxxxxxKeyxxxxxxxxxxxx');
    var nodemailer = require('nodemailer');
    var smtpTransport = require('nodemailer-smtp-transport');
    console.log(req.query);
    //Create a iCal object
    var builder = icalToolkit.createIcsFileBuilder();
    builder.method = 'REQUEST';
    //Name of calander 'X-WR-CALNAME' tag. 
    builder.calname = 'Yo Cal';
    builder.events.push({

        //Event start time, Required: type Date() 
        start: new Date(),

        //Event end time, Required: type Date() 
        end: new Date(req.query.dateOfInterview),
        //Event summary, Required: type String 
        summary: 'Scheduled interview For ' + req.query.name,


        //All Optionals Below 

        //Alarms, array in minutes 
        alarms: [120, 60]
    });
    //builder.method = meeting.method;
    //Add the event data

    var icsFileContent = builder.toString();
    var smtpOptions = {
        "host": "smtp.postmarkapp.com",
        "port": 25,
        "secureConnection": true,
        "auth": {
            user: 'username',
            pass: 'password'
        }
    };

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

    var mailOptions = {
        from: '******',
        to: req.query.tpMail,
        alternatives: [{
            contentType: 'text/calendar; charset="utf-8"; method=REQUEST',
            content: icsFileContent.toString()
        }]
    };

    //send mail with defined transport object 

    transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
            console.log(error);
        } else {
            console.log('Message sent: ' + info.response);
        }
        res.end();
    });
};

任何帮助,将不胜感激。

4

1 回答 1

1

我的代码都是正确的这里的问题是 nodemailer 之前的版本是 0.7.1,现在将其更改为 2.4.2,如果您想更改 nodemailer 版本,它可以工作:

1)删除nodemailer并再次node_modules运行npm安装。

或者

2)npm remove nodemailer npm install nodemailer2.4.2 --save

于 2016-08-08T10:59:29.933 回答