【问题标题】:Send outlook calendar invite from Rails从 Rails 发送 Outlook 日历邀请
【发布时间】:2014-05-04 17:56:10
【问题描述】:

我正在尝试从我的 Rails 应用程序发送日历邀请。它在 Gmail 中似乎可以正常工作,但在 Outlook 中却不行,它是作为附件发送的。

我已经尝试了 Internet 上的所有建议,但无法实现。

class Notifications < ActionMailer::Base
  def add_interaction
    @i = i
    ical = Icalendar::Calendar.new
    e = Icalendar::Event.new
    e.start = DateTime.now.utc
    e.start.icalendar_tzid="UTC" # set timezone as "UTC"
    e.end = (DateTime.now + 1.hour).utc
    e.end.icalendar_tzid="UTC"
    e.organizer @i.interviewer_email
    e.created = DateTime.now
    e.uid = e.url = "#{HOSTNAME.to_s+'/interaction/'+@i.id.to_s}"
    e.summary "#{INTERACTION_TYPE[@i.itype][0]} with #{@i.company}"
    e.description <<-EOF
    #{INTERACTION_TYPE[@i.itype][0]} with #{@i.company}
    Date: #{@i.start_time.strftime('%e %b %Y')}
    Time: #{@i.start_time.strftime('%I:%M %p')}
    EOF
    ical.add_event(e)
    ical.custom_property("METHOD", "REQUEST")

    email=mail(to: "sample@email.com", subject: "Interview",mime_version: "1.0", content_type:"text/calendar",body:ical.to_ical,content_disposition:"inline; filename=calendar.ics", filename:'calendar.ics')
    email.header=email.header.to_s+'Content-Class:urn: content-classes:calendarmessage'
    return email
  end
end

它被称为

Notifications.add_interaction(Interaction.last).deliver

我也尝试将邮件构造为

    email=mail(to: "nikhil@talentauction.in,nikhil@zobtree.com", subject: "#{@i.bid.company.name} has suggested a time for #{INTERACTION_TYPE[@i.itype][0]}",mime_version: "1.0", content_type:"multipart/alternative",body:'')
    html_body = render_to_string("/notifications/add_interaction")
    email.add_part(
        Mail::Part.new do
            content_type "text/html"
            body html_body
        end
    )
    p = Mail::Part.new do
        content_type 'text/calendar; method=REQUEST name="calendar.ics"'
        content_disposition "inline; filename=calendar.ics"
        content_transfer_encoding "8bit"
        body ical.to_ical
    end
    p.header=p.header.to_s+'Content-Class:urn: content-classes:calendarmessage'
    email.add_part(p)

但在所有情况下,日历邀请都是作为 Outlook 中的附件发送的。

我注意到一些奇怪的东西,这可能是造成这种情况的原因。当我查看电子邮件的来源时,在这两种情况下,最上面的 mimetype 都是multipart/mixed,(而不是第一次是text/calendar,第二次是multipart/alternative

而从控制台发送电子邮件时,它会这样说

Message-ID: <5332b0db144e8_1a80129d7f866915@skynet.mail>
Subject: Talent Auction has suggested a time for Introduction Call
Mime-Version: 1.0
Content-Type: text/calendar;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename=calendar.ics
filename: calendar.ics
Content-Class: urn: content-classes:calendarmessage

BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
CALSCALE:GREGORIAN
PRODID:iCalendar-Ruby
BEGIN:VEVENT
CREATED:20140326T162000
DESCRIPTION:        Introduction Call with Talent Auction\n     Date: 28 Mar 2014\n 
    Time: 04:00 PM\n
DTEND:20140327T105000Z
DTSTAMP:20140326T105000Z
DTSTART:20140326T105000Z
CLASS:PUBLIC
ORGANIZER:nikhil@zobtree.com
SEQUENCE:0
SUMMARY:Introduction Call with Talent Auction
UID:localhost:300019
URL:localhost:300019
END:VEVENT
END:VCALENDAR

编辑:我正在使用 mandrill 发送电子邮件,如果有帮助的话

【问题讨论】:

  • 从控制台发送时,您能否发布带有完整标题的电子邮件来源?

标签: ruby-on-rails ruby-on-rails-4 outlook mime-types actionmailer


【解决方案1】:

Mandrill 无法处理日历邀请,因此它会在您发送电子邮件时将其过滤掉。

来自支持请求:

目前我们无法支持内联消息部分 Outlook 和其他一些电子邮件客户端用于附加日历邀请。 这些客户不是将这些邀请作为单独的文件附加,而是 包括日历邀请作为它自己的消息部分(如文本 部分或消息的 HTML 部分)。当 Mandrill 的解析器命中时 该内联邀请部分,它将跳过它们,因为它们没有 符合它知道如何抽象掉的任何东西。这不是真的 文本或 HTML、附件或嵌入图像。

将来,我们会考虑为此添加特殊支持 特定形式的消息,因为它很受欢迎,但我无法提供 任何具体的预计到达时间。与此同时,你可能 考虑生成 .ics 文件并附加它们,就像您一样 可能通过 Mandrill API 或 SMTP 处理其他类型的附件 整合。

【讨论】:

    【解决方案2】:

    如果以“正确”的方式附加,fair outlook 会愉快地接受事件。现在无法模拟您的设置,所以我只能尝试帮助您进行一些猜测。请尝试:

    email = mail(to: "sample@email.com", subject: "Interview", mime_version: "1.0", content_type: "text/plain", body: ical.to_ical, content_disposition: "attachment; filename='calendar.ics'")
    return email
    

    如果也失败了,请尝试:

    ... content_type: "text/calendar" ...
    

    对于您希望的其他方法:

    p = Mail::Part.new do
        content_type "text/plain; name='calendar.ics'"
        content_disposition "attachment; filename='calendar.ics'"
        content_transfer_encoding "7bit"
        body ical.to_ical
    end
    

    如果失败也请尝试

    ... content_type "text/calendar" ...
    

    改为。

    此外,请记住,发送者需要在接收者的通讯录中才能添加事件而无需确认。此外,http://severinghaus.org/projects/icv/ 有一个 ical 验证器。很想得到您的反馈..

    【讨论】:

    • 将在周末尝试,如果其中任何一项有效,请接受并给予赏金
    • 你有机会瞥见吗?
    • 嘿,对不起。忘记回复了。试过这个,但没有用。因此我投了赞成票,但没有接受
    • 大多数 (90%) 客户正在使用 Google 应用程序,它可以正确呈现。所以在花了太多时间之后终于放弃了这个。当我的负载少一点时可能会稍后回来
    • 谢谢,如果你能指定没有工作的方面,我会尝试进步
    猜你喜欢
    • 2020-03-14
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    相关资源
    最近更新 更多