Mailgun:发送日历会议事件/请求
Mailgun: send calendar meeting event / request
我在发送 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
object 由 ics
库创建并通过以下函数包装在 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 将其正确识别为会议邀请:
但是,其他电子邮件客户端(iOS、Outlook)无法识别这是日历事件邀请,只是将其显示为带有文件附件的普通电子邮件。
我应该怎么做才能使此邮件与 Outlook 和 iOS 兼容?
Outlook(我相信 iOS 也是如此)使用 "alternatives" 来存储邀请。
本 GitHub 期概述了如何使用 MIME 库构建事件消息:https://github.com/bojand/mailgun-js/issues/44。您应该能够使用问题中概述的相同代码流来构建您的消息。您需要使用从 ics.createEvent 返回的字符串值进行“addAlternative”调用。
Mailcomposer 是 Mailgun 文档 (https://documentation.mailgun.com/en/latest/api-sending.html#examples) 中引用的 MIME 库。
我在发送 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
object 由 ics
库创建并通过以下函数包装在 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 将其正确识别为会议邀请:
但是,其他电子邮件客户端(iOS、Outlook)无法识别这是日历事件邀请,只是将其显示为带有文件附件的普通电子邮件。
我应该怎么做才能使此邮件与 Outlook 和 iOS 兼容?
Outlook(我相信 iOS 也是如此)使用 "alternatives" 来存储邀请。
本 GitHub 期概述了如何使用 MIME 库构建事件消息:https://github.com/bojand/mailgun-js/issues/44。您应该能够使用问题中概述的相同代码流来构建您的消息。您需要使用从 ics.createEvent 返回的字符串值进行“addAlternative”调用。
Mailcomposer 是 Mailgun 文档 (https://documentation.mailgun.com/en/latest/api-sending.html#examples) 中引用的 MIME 库。