SimonKiteley
SimonKiteley

Reputation: 369

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.

Upvotes: 6

Views: 3082

Answers (2)

gmcnaughton
gmcnaughton

Reputation: 2293

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: ...)

Upvotes: 5

OneChillDude
OneChillDude

Reputation: 8006

You need to call .deliver! on your mail sending.

mail(to: 'thisguy', from: 'thatguy', subject: 'Hey').deliver!

Upvotes: -1

Related Questions