Atozed Forums

Full Version: Email Calendar Appointments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there

Im trying to email a calendar appointment to outlook, that shows the email as an appointment (with Accept,Decline at the top of the email etc) with an .ics icalendar file attached.  Basically, its the sames as sending an appointment from Googles gmail to MS Outlook.

I can send the email appointment OK with ....


    MailMessage.From.Address := 'mail@server.com';
    MailMessage.Recipients.EMailAddresses := 'lparvin@bjphomesupport.co.uk';
    MailMessage.Subject     := 'Send calendar';
    MailMessage.ContentType := 'text/calendar;method=REQUEST';

I can also send an .ics attatchment with plain text email with ....

    Attachment:=TIdAttachmentFile.Create(MailMessage.MessageParts, CalendarFile) ;
    Attachment.ContentType:='text/calendar';


However, I can NOT combine the two, ie send the email appointment with the .ics file attached.

As soon I set  MailMessage.ContentType to anything other than   'text/calendar;method=REQUEST'; eg change it to 'multipart/alternative', it fails.

Do you have any suggestions on how to send the email with MessageParts, but with the main MailMessage.ConentType = 'text/calendar'.

Many thanks

Lee Parvin
(09-27-2018, 09:23 AM)leeparvin Wrote: [ -> ]I can send the email appointment OK with ....

    MailMessage.From.Address := 'mail@server.com';
    MailMessage.Recipients.EMailAddresses := 'lparvin@bjphomesupport.co.uk';
    MailMessage.Subject     := 'Send calendar';
    MailMessage.ContentType := 'text/calendar;method=REQUEST';

That will only work if you load the *content* of the ICS file into the TIdMessage.Body property.

(09-27-2018, 09:23 AM)leeparvin Wrote: [ -> ]I can also send an .ics attatchment with plain text email with ....

    Attachment:=TIdAttachmentFile.Create(MailMessage.MessageParts, CalendarFile) ;
    Attachment.ContentType:='text/calendar';

That should work fine, after you add the missing 'method' attribute:

Code:
Attachment.ContentType := 'text/calendar;method=REQUEST';

(09-27-2018, 09:23 AM)leeparvin Wrote: [ -> ]However, I can NOT combine the two, ie send the email appointment with the .ics file attached.

As soon I set  MailMessage.ContentType to anything other than   'text/calendar;method=REQUEST'; eg change it to 'multipart/alternative', it fails.

See Multipart email with text and calendar: Outlook doesn't recognize ics.

If you still can't get it to work, then please show your complete code to populate the TIdMessage.
(09-27-2018, 08:11 PM)rlebeau Wrote: [ -> ]
(09-27-2018, 09:23 AM)leeparvin Wrote: [ -> ]I can send the email appointment OK with ....

    MailMessage.From.Address := 'mail@server.com';
    MailMessage.Recipients.EMailAddresses := 'lparvin@bjphomesupport.co.uk';
    MailMessage.Subject     := 'Send calendar';
    MailMessage.ContentType := 'text/calendar;method=REQUEST';

That will only work if you load the *content* of the ICS file into the TIdMessage.Body property.

(09-27-2018, 09:23 AM)leeparvin Wrote: [ -> ]I can also send an .ics attatchment with plain text email with ....

    Attachment:=TIdAttachmentFile.Create(MailMessage.MessageParts, CalendarFile) ;
    Attachment.ContentType:='text/calendar';

That should work fine, after you add the missing 'method' attribute:

Code:
Attachment.ContentType := 'text/calendar;method=REQUEST';

(09-27-2018, 09:23 AM)leeparvin Wrote: [ -> ]However, I can NOT combine the two, ie send the email appointment with the .ics file attached.

As soon I set  MailMessage.ContentType to anything other than   'text/calendar;method=REQUEST'; eg change it to 'multipart/alternative', it fails.

See Multipart email with text and calendar: Outlook doesn't recognize ics.

If you still can't get it to work, then please show your complete code to populate the TIdMessage.

Hi Remy

Still no luck.  However, by setting the attachment contenttype = 'text/plain' instead of 'text/calendar' fixed the problem.

Just to confirm, Im trying to copy the Google to Outlook setup ie calendar event with an .ics attatchment.

Please see below for a stripped out version, which I hope makes sense.  Please see

ie

......

    idlMessage.Subject     := 'Send calendar';
    idlMessage.ContentType := 'multipart/mixed';


    idTextPart := TIdText.Create(MailMessage.MessageParts, nil);
    idTextPart.ContentType := 'multipart/alternative';


    idTextPart:= TIdText.Create(MailMessage.MessageParts);
    idTextPart.ContentType:= 'text/plain';
    idTextPart.ParentPart := 0;
    idTextPart.Body.Append('Test');


    idTextPart:= TIdText.Create(MailMessage.MessageParts);
    idTextPart.ContentType:= 'text/calendar;method=REQUEST';
    idTextPart.ParentPart := 0;

    idTextPart.Body.Append('BEGIN:VCALENDAR');
.....
    idTextPart.Body.Append('END:VCALENDAR');



    Calendar.Append('BEGIN:VCALENDAR');
......
    Calendar.Append('END:VCALENDAR');

    Calendar.SaveToFile(CalendarFile);

    Attachment:=TIdAttachmentFile.Create(MailMessage.MessageParts, CalendarFile);
    Attachment.ContentType:='text/plain';  -< THIS WORKED!!!!
////    Attachment.ContentType:='text/calendar';  -< THIS DID NOT WORK!!!
    Attachment.FileName := CalendarFile;



I hope this makes sense.......

Thanks

Lee
(09-28-2018, 10:26 AM)leeparvin Wrote: [ -> ]Still no luck.  However, by setting the attachment contenttype = 'text/plain' instead of 'text/calendar' fixed the problem.

But then it won't be identified as an ICS file anymore by automated processors.  The "Content-Type" matters.

(09-28-2018, 10:26 AM)leeparvin Wrote: [ -> ]    idTextPart.Body.Append('BEGIN:VCALENDAR');
.....
    idTextPart.Body.Append('END:VCALENDAR');

    Calendar.Append('BEGIN:VCALENDAR');
......
    Calendar.Append('END:VCALENDAR');

    Calendar.SaveToFile(CalendarFile);

You don't need to duplicate the calendar data like that.  I would populate just the Calendar object and then Assign() it to idTextPart.Body.  Or get rid of the Calendar object and call idTextPart.Body.SaveToFile().

On the other hand, you don't need a temp file at all if you use TIdAttachmentMemory instead of TIdAttachmentFile.

(09-28-2018, 10:26 AM)leeparvin Wrote: [ -> ]    Attachment:=TIdAttachmentFile.Create(MailMessage.MessageParts, CalendarFile);
    Attachment.ContentType:='text/plain';  -< THIS WORKED!!!!
////    Attachment.ContentType:='text/calendar';  -< THIS DID NOT WORK!!!
    Attachment.FileName := CalendarFile;

You are missing the 'method' attribute again on the ContentType.  That attribute is REQUIRED by RFC 6047 Section 2.4.