【问题标题】:Mailgun: send calendar meeting event / requestMailgun:发送日历会议事件/请求
【发布时间】:2017-11-04 13:51:07
【问题描述】:

我在发送 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 正确地将其识别为会议邀请:

但是,其他电子邮件客户端(iOS、Outlook)无法识别这是日历活动邀请,只是将其显示为带有文件附件的普通电子邮件。

我应该怎么做才能使此邮件与 Outlook 和 iOS 兼容?

【问题讨论】:

    标签: javascript outlook calendar mailgun meeting-request


    【解决方案1】:

    Outlook(我相信 iOS 也是如此)使用“替代方案”来存储邀请。

    此 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 库。

    【讨论】:

    • 嗨 Joe P。您提到的 GitHub 问题来自 2014 年 9 月,指的是不再支持的旧版 mailgun lib
    • @Pawel 尽管 GitHub 问题的年代久远,但方法应该仍然相同。要回答您帖子中的问题(我应该怎么做才能使此消息与 Outlook 和 iOS 兼容?):您需要发送一条消息,其中包含存储在 MIME 消息中的事件信息。在 mailgun-js 自述文件中有一个这样的例子:github.com/bojand/mailgun-js#sending-mime-messages。他们引用的邮件撰写库支持替代方案 (nodemailer.com/message/alternatives) 并具有 iCal 事件的特定属性 (nodemailer.com/message/calendar-events)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2013-06-09
    • 1970-01-01
    • 2019-03-02
    • 2015-07-27
    • 2019-01-02
    • 1970-01-01
    相关资源
    最近更新 更多