ruby-on-rails – 从Rails发送Outlook日历邀请

我正在尝试从我的Rails应用程序发送日历邀请.它似乎在Gmail中正常工作,但在outlook中却没有,它作为附件发送.

我已经尝试过互联网上的所有建议,但是无法让它发挥作用.

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]}",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,(第一次代替文本/日历,第二次代替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发送电子邮件,如果这将有任何帮助

解决方法

如果以“正确”的方式附加事件,我们会愉快地接受事件.不能立即模拟你的设置,所以我可以尝试帮助有点猜测..请尝试:
email = mail(to: "sample@email.com",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验证器.很想得到你的反馈..

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...