Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: Creating an email for an event using iCalendar. Google does not recognise it

Maybe its not something that google does anymore! I have the following code.

mail(from: @process_action.finance_case.case_owner.user.email, to: @process_action.finance_case.case_owner.user.email, subject: "Appointment") do |format|
   format.ics {
   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.day).utc
   e.end.icalendar_tzid="UTC"
   e.organizer "[email protected]"
   e.uid "MeetingRequest#{unique_value}"
   e.summary "Scrum Meeting"
   ical.add_event(e)
   ical.publish
   ical.to_ical
   render :text => ical.to_ical
  }
end

Have tried setting the content type to text/calendar and a few other randon changes to see if it helped. Someone suggest the 'method' should be set to REQUEST for google to recognise but not sure how or where.

Any help/pointers would be gratefully received. Or even if it would work in Outlook as that is what the client uses.

UPDATE: Not to clear above but the email is being delivered. Its google that is failing to recognise it as an event invite.

like image 682
SimonKiteley Avatar asked Jan 06 '14 16:01

SimonKiteley


1 Answers

Rather than providing the ics information as a format block, what worked for me was to add it to the email as an attachment. Gmail then shows it as an attached event under an "Events in this message" block:

# Generate the calendar invite
ical = Icalendar::Calendar.new
e = Icalendar::Event.new
...
ical.add_event(e)
ical.publish

# Add the .ics as an attachment
attachments['event.ics'] = { mime_type: 'application/ics', content: ical.to_ical }

# Generate the mail
mail(from: ..., to: ...)
like image 123
gmcnaughton Avatar answered Sep 18 '22 14:09

gmcnaughton