-2

Could someone provide me with a full/working example of a snippet/function (PHP or Classic ASP) that sends a meeting invite (compatible with Outlook) using JMail?

PC-Gram
  • 81
  • 1
  • 2
  • 11
  • 1
    This isn't a "write my code for me" site. You are expected to show that you have researched the issue and tried coding it. If you have an issue in your code you can't solve, then you post a question specific to that problem. There are plenty of examples how to create .cal file attachments out there – Dijkgraaf Nov 12 '15 at 19:29
  • Believe me I've spent hours finding nothing. A generalized code example would not only help me but be inspiring to many other programmers – PC-Gram Nov 12 '15 at 19:39
  • There are two pars to the problem 1) Creating a the calendar file e.g. PHP example using Swift Mailer here using PHP. http://stackoverflow.com/questions/29954123/send-ics-calendar-invite-using-swift-mailer-and-send-grid?rq=1 2) Sending out out via JMail, but that is just a matter of adding the file as an attachment with whatever mail client. I've done it previously in Classic ASP with only a couple of hours research. Look for iCalendar https://en.wikipedia.org/wiki/ICalendar – Dijkgraaf Nov 12 '15 at 19:52

1 Answers1

1

Here is the function I created for my solution in Classic ASP for creating a calendar file.

You will have to customize it. e.g. the fmtDateTime & FmtDate are custom functions to format the date. You will need to use your own functions for that. Also I had some things hard coded (e.g. NAME OF SENDING APPLICATION, SENDER NAME & SENDER EMAIL) but you can make those parameters easily enough. And you will want to set the appropriate time zone as well.

Function WriteICSFile(CalendarFileName,startdate,enddate,starttime,endtime,description,summary,venue)

    If enddate = "" Then enddate = startdate

    startdate = startdate & " " & starttime
    enddate = enddate & " " & endtime
    txtNow = fmtDateTime(now(),"yyyy-mm-dd hh:mm:ss")
    txtNow = Replace(Replace(Replace(txtNow,"-","")," ","T"),":","")

    txtStartDate=FmtDate(startdate,"%Y%M%DT%H%N00") 
    txtEndDate=FmtDate(enddate,"%Y%M%DT%H%N00")

    Contents = "BEGIN:VCALENDAR" & vbCRLF &_
        "VERSION:2.0" & vbCRLF &_
        "PRODID:-//NAME OF SENDING APPLICATION//EN" & vbCRLF &_
        "BEGIN:VEVENT" & vbCRLF &_
        "UID:Event" & intEvents & vbCRLF &_
        "DTSTAMP;TZID=Pacific/Auckland:" & txtNow & vbCRLF &_
        "ORGANIZER;CN=SENDER NAME:MAILTO:SENDER EMAIL" & vbCRLF &_
        "DTSTART;TZID=Pacific/Auckland:" & txtStartDate & vbCRLF &_
        "DTEND;TZID=Pacific/Auckland:" & txtEndDate & vbCRLF &_
        "DESCRIPTION:" & description & vbCRLF &_
        "SUMMARY:" & summary & vbCRLF &_
        "LOCATION:" & venue & vbCRLF &_
        "END:VEVENT" & vbCRLF &_
        "END:VCALENDAR"  & vbCRLF


        set oFs = server.createobject("Scripting.FileSystemObject")
        set oTextFile = oFs.OpenTextFile(CalendarFileName, 2, True)
        oTextFile.Write Contents
        oTextFile.Close
        set oTextFile = nothing
        set oFS = nothing       
End Function
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
  • Thanks for the snippet. With this I can produce an .ics-file and attach it to an email. This, however, will only make the email appear as an ordinary email with an attachment, that the user will have to administer. Next step for me is to put the iCalendar into an email so it will appear as an invite. Then my users can setup their account to automatically accept my invites. In this respect I have some trouble controlling the ContentType attribute in JMail.Message – PC-Gram Nov 13 '15 at 16:51
  • The appearing as an invite is what the client application does, it is not something that you can control as far as I know. By just attaching an .ics file to an email, in GMail it shows as an invitation. Others apparently only support the older vCalendar specification (see http://stackoverflow.com/questions/16063720/outlook-doesnt-recognise-ical-attachment) – Dijkgraaf Nov 15 '15 at 19:24
  • A native Outlook invite appears the same way as an .ics-attachment does when opened, and it does not have an attachment. Thus I recon that the .ics-part is a multipart of the email. Btw: In your snippet I would suggest using msg.addCustomAttachment (JMail). Then you can create an attachment without involving access to the file system. – PC-Gram Nov 16 '15 at 16:50