javascript - Mailgun:发送日历 session 事件/请求

标签 javascript outlook calendar mailgun meeting-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 对象由 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 邀请:

enter image description here

但是,其他电子邮件客户端(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/

相关文章:

.net - COM Interop无需再充气

html - Angular-bootstrap 日历 mwl -> 事件的其他符号而不是点

javascript - 使用原型(prototype)与直接在构造函数中定义方法相比有何优点?

javascript - 使用 jQuery 动态添加视频元素

javascript - 使用 javascript 或 jquery 即时创建 .ics 文件?

android - 在 getDisplayNames() 中使用 Calender.LONG 未解决

php - PHP 中的日历日 View

javascript - 我如何通过外部javascript调用用reactjs编写的函数?

javascript - 创建 JSON 对象的排列?

C# 检查 Outlook 邮件项目是否是真正的 MailItem