我需要设置一个Outlook日历活动,我正在使用邮戳SMTP服务 我使用iCalToolkit创建了一个日历对象。
但在这里我收到错误[没有定义传输方法] 几天前它正常工作但今天开始显示错误。 我正在使用快递框架 我不明白这个问题
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();
});
};
任何帮助都将不胜感激。
答案 0 :(得分:1)
我的代码都是正确的 这里的问题是nodemailer版本 在它是0.7.1之前,现在将它改为2.4.2并且它起作用了 如果你想更改你的nodemailer版本,那么:
1)删除nodemailer
下的node_modules
并再次运行npm
安装。
或强>
2)npm remove nodemailer
npm install nodemailer2.4.2 --save