Javascript Mailgun:发送日历会议事件/请求
我在发送Outlook和iOS邮件应用程序识别为日历事件而不是普通电子邮件的日历事件时遇到问题 我正在node.js env中使用JavaScript。要发送电子邮件,我使用mailgun和js库Javascript Mailgun:发送日历会议事件/请求,javascript,outlook,calendar,mailgun,meeting-request,Javascript,Outlook,Calendar,Mailgun,Meeting Request,我在发送Outlook和iOS邮件应用程序识别为日历事件而不是普通电子邮件的日历事件时遇到问题 我正在node.js env中使用JavaScript。要发送电子邮件,我使用mailgun和js库mailgun js。我正在创建ics文件并将其附加到电子邮件中 const mailgun = require('mailgun-js')({apiKey: mailgunApiKey, domain: mailgunDomain}) const candidateEmailBody = {
mailgun js
。我正在创建ics文件并将其附加到电子邮件中
const mailgun = require('mailgun-js')({apiKey: mailgunApiKey, domain: mailgunDomain})
const candidateEmailBody = {
from: `${companyName} <${EMAIL_FROM}>`,
to: email,
subject: companyName + ' - interview',
html: 'Html message',
attachment: [invite]
}
mailgun.messages().send(candidateEmailBody, function (error, body) {
if (error) {
console.log(error)
}
})
以这种方式准备的电子邮件通过mailgun API发送,GMail正确地将其识别为会议邀请:
但是,其他电子邮件客户端(iOS、Outlook)不知道这是日历事件邀请,只是将其显示为普通电子邮件,并带有文件附件
我应该怎么做才能使此邮件与Outlook和iOS兼容?Outlook(我相信iOS也一样)使用“备选方案”来存储邀请
此GitHub问题概述了如何使用MIME库构建事件消息:。您应该能够使用本期文章中概述的相同代码流来构建消息。对于“addAlternative”调用,需要使用从ics.createEvent返回的字符串值
Mailcomposer是Mailgun文档()中引用的MIME库。Hi Joe p。您提到的GitHub问题来自2014年9月,指的是Mailgun库的旧版本,该版本已不再存在supported@Pawel尽管GitHub问题已经过时,但方法应该还是一样的(如何使此邮件Outlook和iOS兼容?):您需要发送一封包含MIME邮件中存储的事件信息的邮件。mailgun js自述文件中有一个例子:。他们引用的邮件组合库支持备选方案()并具有iCal事件()的特定属性。
const prepareIcsInvite = function (startDate, companyName, firstname, lastname, email, intFirstname, intLastname, intEmail) {
const st = new Date(startDate)
const meetingEvent = {
start: [st.getFullYear(), st.getMonth() + 1, st.getDate(), st.getHours(), st.getMinutes()],
end: [st.getFullYear(), st.getMonth() + 1, st.getDate(), st.getHours()+1, st.getMinutes()],
title: companyName + ' - Interview',
description: 'description',
location: 'location',
status: 'CONFIRMED',
productId: 'myproduct',
organizer: {name: 'Admin', email: 'admin@example.com'},
attendees: [
{name: firstname + ' ' + lastname, email: email},
{name: intFirstname + ' ' + intLastname, email: intEmail}
]
}
const icsFile = ics.createEvent(meetingEvent)
const fileData = new Buffer(icsFile.value)
const invite = new mailgun.Attachment(
{
data: fileData,
filename: 'Meeting Invite.ics',
contentType: 'text/calendar'
})
console.log('ICS meeting invite created')
return invite
}