                 html:    htmlTemplate templateOptions
                 content: localization.t templateKey, templateOptions
 
-            # Send mail through CozyDB API
-            cozydb.api.sendMailFromUser mailOptions, (err) ->
-                if err
-                    log.error "An error occured while sending invitation"
+            # Attach event as ics file
+            calendarOptions =
+                organization:'Cozy Cloud'
+                title: 'Cozy Calendar'
+            calendar = new VCalendar calendarOptions
+            calendar.add event.toIcal()
+            icsPath = path.join os.tmpdir(), 'invite.ics'
+            fs.writeFile icsPath, calendar.toString(), (err) ->
+                if (err)
+                    log.error """
+                      An error occured while creating invitation file #{icsPath}
+                    """
                     log.error err
                 else
-                    needSaving   = true
-                    guest.status = 'NEEDS-ACTION' # ical = waiting an answer
+                    mailOptions.attachments = [
+                        contentType: 'text/calendar'
+                        path: icsPath
+                    ]
 
-                done err
+                # Send mail through CozyDB API
+                cozydb.api.sendMailFromUser mailOptions, (err) ->
+                    if err
+                        log.error "An error occured while sending invitation"
+                        log.error err
+                    else
+                        needSaving   = true
+                        guest.status = 'NEEDS-ACTION' # ical = waiting an answer
+
+                    fs.unlink icsPath, (errUnlink) ->
+                        if errUnlink
+                            log.error "Error deleting ics file #{icsPath}"
+                        done err
 
         # Catch errors when doing async foreach
         , (err) ->

async = require 'async'
jade = require 'jade'
fs = require 'fs'
log = require('printit')
    prefix: 'MailHandler'
    date: true

Event = require '../models/event'
User = require '../models/user'
cozydb = require 'cozydb'

localization = require '../libs/localization_manager'


                date: date
            htmlTemplate = localization.getEmailTemplate 'mail_delete'
            subjectKey = 'email delete title'
            subject = localization.t subjectKey, description: event.description
            mailOptions =
                to: guest.email
                subject: subject
                content: localization.t 'email delete content', templateOptions
                html: htmlTemplate templateOptions
            cozydb.api.sendMailFromUser mailOptions, (err) ->
