How to create a multi-page email? [Rails]

I want to achieve the following:

Send an email with delayed_job containing:

  • plain text
  • html (will be displayed by regular customers who do not understand the built-in)
  • "built-in" that is recognized by Outlook and Thunderbird (using Lightning). Thunderbird Accept / Decline / Tentative Buttons
  • "regular" attachment (for # 2)

What works so far / what does'nt:

I can send an email via delayed_job with all parts, however:

  • in Apple Mail 2 applications are displayed (instead of one):

Apple mail

(html displays ok)

  • in Thunderbird (Lightning) I get an invitation, just like I want. But the alarm is not displayed.

Lightning

  • gsubs iCal, ATTENDEES. (. )

:

, : _job

, : content_type "multipart/mixed"

MIME-:

  • /
    • /
      • /
      • /HTML
      • / ( : method = REQUEST)
    • /

! .

:

: Rails 4.2 (attachments mail)

mailer.rb

def invitation_email(...)  
  subject = "I suck at email..."
  attachments["invite.ics"] = { mime_type: "application/ics",
                                content: ical_attachment }
  email = mail(from: me, to: you, subject: subject)
  add_ical_part_to(email)
  email
end

def add_ical_part_to(mail)
  outlook_body = ical_attachment
  mail.add_part(Mail::Part.new do
    content_type "text/calendar; method=REQUEST"
    body outlook_body
  end)
end

, :

def ical_attachment
  params_participant = {
        "ROLE"   => "REQ-PARTICIPANT",
        "RSVP" => "FALSE",
        "PARTSTAT" => "ACCEPTED"
  }

  params_invite = {
        "CUTYPE" => 'INDIVIDUAL',
        "ROLE"   => "REQ-PARTICIPANT",
        "PARTSTAT" => "NEEDS-ACTION",
        "RSVP" => "TRUE"
  }

  cal = Icalendar::Calendar.new

  event = Icalendar::Event.new
  event.dtstart      @party.from.to_datetime, { "VALUE" => "DATE" }
  event.dtend        @party.to.to_datetime, { "VALUE" => "DATE" }
  event.summary      @party.title
  event.description  @party.description
  event.klass        "PRIVATE"
  event.organizer    "cn=#{@user.name} #{@user.surname}:mailto:#{@user.email}"

    # THIS DOES NOT WORK
  event.alarm.trigger =  "-PT5M" # 5 Minutes before...

  @party.participations.each do |participation|
        str = "cn=#{participation.user.name} #{participation.user.surname}:mailto:#{participation.user.email}"
        event.add_attendee(str, params_participant)
  end

  @party.invitations.each do |invitee|
        event.add_attendee("mailto:#{invitee.email}", params_invite)
  end
  cal.add_event(event)
  cal.publish

  # I KNOW THIS IS HORRIBLE AND I HATE IT, BUT OTHERWISE THE ATTENDEES DO NOT SHOW UP
  cal.to_ical.gsub("ORGANIZER:", "ORGANIZER;").gsub("ACCEPTED:", "ACCEPTED;").gsub("TRUE:", "TRUE;").gsub("PUBLISH", "REQUEST")
end

!

: http://pastebin.com/patf05zd

, :

+4
2

- , :

icalendar gem ri_cal. , 3 , google .

ical ( , ), , , ( , , :))

def to_ical
# this is horrible
klass = self

cal = RiCal.Calendar do
  event = event do
    organizer   "CN=#{klass.user.name} #{klass.user.surname}:mailto:#{klass.user.email}"
    summary     klass.party.title

    description klass.ical_description
    dtstart     klass.party.from.utc.to_datetime
    dtend       klass.party.to.utc.to_datetime
    location    "See url in description"
    security_class klass.security_class

    # this is horrible
    h = self

    klass.party.participations.each do |participation|
      h.add_attendee klass.prepare_participant(participation)
    end

    klass.party.invitations.each do |invitee|
      h.add_attendee klass.prepare_invitee(invitee.email)
    end

    unless klass.party.reminder == 0
      alarm do
        description "Alarm description"
        trigger klass.convert_trigger # -PT1H
        action "DISPLAY"
      end
    end
  end
end

# THE HORROR
cal.to_s.gsub("ATTENDEE:", "ATTENDEE")
        .gsub("ORGANIZER:", "ORGANIZER;")
        .gsub("CALSCALE:GREGORIAN", "CALSCALE:GREGORIAN\nMETHOD:REQUEST\n")

2 "" , , .

+2

B64 ( ). Thunderbird.

, , . , . .

Apple iCal, , : , ics, - , . / iCal?

+1

Source: https://habr.com/ru/post/1529250/


All Articles