我在发送 Outlook 和 iOS 邮件应用识别为日历事件而非普通电子邮件的日历事件时遇到问题。
我在 node.js 环境中使用 JavaScript。要发送电子邮件,我正在使用 mailgun 和 js 库 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)
}
})
invite
对象由 ics
lib 创建并通过以下函数包装在 mailgun 附件中:
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
}
以这种方式准备的电子邮件是通过 mailgun API 发送的,GMail 会正确地将其识别为 session 邀请:
但是,其他电子邮件客户端(iOS、Outlook)无法识别这是日历事件邀请,只是将其显示为带有文件附件的普通电子邮件。
我应该怎么做才能使此邮件与 Outlook 和 iOS 兼容?
最佳答案
Outlook(我相信 iOS 也是如此)使用“替代方案”来存储邀请。
此 GitHub 问题概述了如何使用 MIME 库构建事件消息:https://github.com/bojand/mailgun-js/issues/44 .您应该能够使用问题中概述的相同代码流来构建您的消息。对于“addAlternative”调用,您需要使用从 ics.createEvent 返回的字符串值。
Mailcomposer 是 Mailgun 文档 ( https://documentation.mailgun.com/en/latest/api-sending.html#examples ) 中引用的 MIME 库。
关于javascript - Mailgun:发送日历 session 事件/请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47111467/