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

llew8vvj  于 2023-05-02  发布在  Ruby
关注(0)|答案(4)|浏览(112)

我正在尝试从Rails应用程序发送日历邀请。它在Gmail中似乎工作得很好,但在Outlook中就不行了,在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]}",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发送电子邮件,如果这将是任何帮助

nkhmeac6

nkhmeac61#

afair 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验证器。好奇地想得到你的反馈。.

izj3ouym

izj3ouym2#

Mandrill无法处理日历邀请,因此在发送电子邮件时会将其过滤掉。
来自支持请求:
目前,我们无法支持Outlook和其他一些电子邮件客户端用于附加日历邀请的内联邮件部分。这些客户端不是将这些邀请作为单独的文件附加,而是将日历邀请作为其自己的消息部分(如消息的文本部分或HTML部分)。当Mandrill的解析器命中内联邀请部分时,它将跳过它们,因为它们不符合它知道如何抽象的任何内容。它不是真正的文本或HTML,附件或嵌入式图像。
在未来,我们将考虑为这种特殊形式的消息添加特殊支持,因为它非常流行,但我不能提供任何具体的ETA。同时,您可以考虑生成。ics文件并附加它们,就像您通过Mandrill API或SMTP集成处理其他类型的附件一样。

ogq8wdun

ogq8wdun3#

在各种主题的多个信息之后,我最终使其工作:

mail to: "xx@outlook.com",
     subject: 'first event outlook',
     mime_version: '1.0',
     content_type: 'text/calendar; method=REQUEST; charset=UTF-8; component=VEVENT',
     body: cal.to_ical,
     content_disposition: "attachment; filename='calendar.ics'"
z9zf31ra

z9zf31ra4#

下面是我在Rails 6上的工作。1,使用ApplicationMailer并使用icalendar gem v2创建.ics文件。8.0:

## InviteMailer < ApplicationMailer

def invite
  ... ## creating icalendar calendar and event

  attachments['event.ics'] = {
    mime_type: 'multipart/mixed', ## important because we are sending html and text files for the body in addition to the actual attachment
    content_type: 'text/calendar; method=REQUEST; charset=UTF-8; component=VEVENT',
    content_disposition: 'attachment; filename=event.ics',
    content: ical.to_ical
  }

  mail(
    to: user.email,
    subject:  "Email subject..."
  )
end

它可以很好地与Gmail和Outlook。

相关问题