我正在使用Angular和Node开发一个非常基本的日历,但我没有找到任何代码。
工作流程如下:创建一个事件,输入收件人的电子邮件地址,验证事件。 这会触发发送给收件人的电子邮件。邮件应采用Outlook会议请求格式(不是附加对象)。
这意味着当在Outlook中收到会议时,会议将自动添加到日历中。
这可能吗?如果是,只有节点端的javascript可以吗?
答案 0 :(得分:7)
对于那些仍在寻找答案的人来说,这就是我如何设法为我找到完美的解决方案。 我使用iCalToolkit创建了一个日历对象。
确保设置所有相关字段非常重要(组织者和RSVP参加者)。
最初我使用Postmark API服务发送我的电子邮件,但此解决方案仅通过发送ics.file附件来工作。
我切换到邮戳SMTP服务,您可以在邮件中嵌入iCal数据,为此我使用了nodemailer。
这就是它的样子:
var icalToolkit = require('ical-toolkit');
var postmark = require('postmark');
var client = new postmark.Client('xxxxxxxKeyxxxxxxxxxxxx');
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
//Create a iCal object
var builder = icalToolkit.createIcsFileBuilder();
builder.method = meeting.method;
//Add the event data
var icsFileContent = builder.toString();
var smtpOptions = {
host:'smtp.postmarkapp.com',
port: 2525,
secureConnection: true,
auth:{
user:'xxxxxxxKeyxxxxxxxxxxxx',
pass:'xxxxxxxPassxxxxxxxxxxx'
}
};
var transporter = nodemailer.createTransport(smtpTransport(smtpOptions));
var mailOptions = {
from: 'message@domain.com',
to: meeting.events[0].attendees[i].email,
subject: 'Meeting to attend',
html: "Anything here",
text: "Anything here",
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);
}
});
这会发送一个真实的会议请求,其中包含“接受”,“拒绝”和“拒绝”按钮。
真正令人难以置信的是,您需要完成这些微不足道的功能所需的工作量以及所有这些都没有详细记录。 希望这会有所帮助。
答案 1 :(得分:3)
如果您不想在早期接受的解决方案中使用smtp服务器方法,则可以使用Exchange聚焦解决方案。当前接受的答案有什么不对?它不会在发件人日历中创建会议,您没有会议项目的所有权以供发件人Outlook / OWA进一步修改。
这是使用npm包ews-javascript-api
var ews = require("ews-javascript-api");
var credentials = require("../credentials");
ews.EwsLogging.DebugLogEnabled = false;
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
exch.Credentials = new ews.ExchangeCredentials(credentials.userName, credentials.password);
exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");
var appointment = new ews.Appointment(exch);
appointment.Subject = "Dentist Appointment";
appointment.Body = new ews.TextBody("The appointment is with Dr. Smith.");
appointment.Start = new ews.DateTime("20170502T130000");
appointment.End = appointment.Start.Add(1, "h");
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("user1@constoso.com");
appointment.RequiredAttendees.Add("user2@constoso.com");
appointment.OptionalAttendees.Add("user3@constoso.com");
appointment.Save(ews.SendInvitationsMode.SendToAllAndSaveCopy).then(function () {
console.log("done - check email");
}, function (error) {
console.log(error);
});
答案 2 :(得分:1)
我不是使用“ ical-generator”,而是使用“ ical-toolkit”来构建日历邀请事件。 使用此方法,邀请直接添加到电子邮件中,而不是附加的.ics文件对象。
这是示例代码:
const icalToolkit = require("ical-toolkit");
//Create a builder
var builder = icalToolkit.createIcsFileBuilder();
builder.method = "REQUEST"; // The method of the request that you want, could be REQUEST, PUBLISH, etc
//Add events
builder.events.push({
start: new Date(2020, 09, 28, 10, 30),
end: new Date(2020, 09, 28, 12, 30),
timestamp: new Date(),
summary: "My Event",
uid: uuidv4(), // a random UUID
categories: [{ name: "MEETING" }],
attendees: [
{
rsvp: true,
name: "Akarsh ****",
email: "Akarsh **** <akarsh.***@abc.com>"
},
{
rsvp: true,
name: "**** RANA",
email: "**** RANA <****.rana1@abc.com>"
}
],
organizer: {
name: "A****a N****i",
email: "A****a N****i <a****a.r.n****i@abc.com>"
}
});
//Try to build
var icsFileContent = builder.toString();
//Check if there was an error (Only required if yu configured to return error, else error will be thrown.)
if (icsFileContent instanceof Error) {
console.log("Returned Error, you can also configure to throw errors!");
//handle error
}
var mailOptions = { // Set the values you want. In the alternative section, set the calender file
from: obj.from,
to: obj.to,
cc: obj.cc,
subject: result.email.subject,
html: result.email.html,
text: result.email.text,
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);
}
});
答案 3 :(得分:0)
答案 4 :(得分:0)
请检查以下示例:
const options = {
authProvider,
};
const client = Client.init(options);
const onlineMeeting = {
startDateTime: '2019-07-12T14:30:34.2444915-07:00',
endDateTime: '2019-07-12T15:00:34.2464912-07:00',
subject: 'User Token Meeting'
};
await client.api('/me/onlineMeetings')
.post(onlineMeeting);