none
How to properly send a message to outlook with an ics file and calendar part? RRS feed

  • Question

  • I need to send an email with both a calendar alternate view and the same .ics file. When I send the email without any attachment, calendar event preview is displayed well.But when I add any kind of attachment, calendar preview dissapeares and I can only see the attach preview. How to do so that two parts are visible.

    It's only in outlook.com in other services the code below works perfect.

    static void Main(string[] args)
        {
            var client = new SmtpClient();
    
            Console.WriteLine("connection success");
            // Now Contruct the ICS file using string builder
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("fromemail@gmail.com", "Sender's Name");
            msg.To.Add(new MailAddress("example@outlook.com", "To Name"));
            msg.Subject = "Send mail with ICS file as an Attachment";
            msg.Body = "Please Attend the meeting with this schedule";
            StringBuilder str = new StringBuilder();
            str.AppendLine("BEGIN:VCALENDAR");
            str.AppendLine("PRODID:-//Schedule a Meeting");
            str.AppendLine("VERSION:2.0");
            str.AppendLine("METHOD:REQUEST");
            str.AppendLine("BEGIN:VEVENT");
            str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+10)));
            str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
            str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+60)));
            str.AppendLine("LOCATION: CGI");
            str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
            str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
            str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
            str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
            str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));
    
            str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address));
    
            str.AppendLine("BEGIN:VALARM");
            str.AppendLine("TRIGGER:-PT15M");
            str.AppendLine("ACTION:DISPLAY");
            str.AppendLine("DESCRIPTION:Reminder");
            str.AppendLine("END:VALARM");
            str.AppendLine("END:VEVENT");
            str.AppendLine("END:VCALENDAR");
    
            System.Net.Mime.ContentType contype = new System.Net.Mime.ContentType("text/calendar");
            contype.Parameters.Add("method", "REQUEST");
            contype.Parameters.Add("name", "Meeting.ics");
            AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), contype);
            msg.AlternateViews.Add(avCal);
    
            //Byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str.ToString());
            //var ms = new System.IO.MemoryStream(bytes);            
            //msg.Attachments.Add(new Attachment(ms, contype));
    
            client.Send(msg);
            //ms.Close();
            Console.WriteLine("Sent");
            Console.ReadLine();
        }




    • Edited by datrax Tuesday, June 16, 2015 12:31 PM
    • Moved by CoolDadTx Tuesday, June 16, 2015 5:38 PM Office related
    Tuesday, June 16, 2015 12:12 PM

All replies

  • Hi datrax,

    >> It's only in outlook.com in other services the code below works perfect.

    What do you mean by “outlook.com”? Do you mean the email address of the receiver is “outlook.com”? If so, could you share us how you open the email? Do you open it in Outlook online, outlook client or with other email client?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, June 17, 2015 8:50 AM
  • Hello, I mean if I open it in Outlook online.
    • Edited by datrax Wednesday, June 17, 2015 11:51 AM
    Wednesday, June 17, 2015 11:50 AM
  • Hi datrax,

    >> When I send the email without any attachment, calendar event preview is displayed well.But when I add any kind of attachment, calendar preview dissapeares and I can only see the attach preview

    What do you mean by “calendar event preview and attach preview”? Could you share us a screen shot about the correct situation and non-work situation? I will recommend you send a message to outlook.com manually with a calendar alternate view, the same .ics file and attachment to check whether the outlook Online could work. If it could not work, I am afraid that the outlook Online did not support this function and if this is a feature you want to include in future versions of Outlook Online, please submit a feedback as picture below:

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, June 18, 2015 9:49 AM
  • ok, sorry for a long reply,was waiting untill my account get verified

    when I send an invitation with a calendar block it shows in preview 

    but as soon as I add any kind of attachment it displayes message like this:


    Wednesday, July 8, 2015 9:24 AM
  • And what I wanna get is simmilar to this (Event created in google calendar):
    Wednesday, July 8, 2015 9:26 AM
  • Hi datrax,

    This forum is for Developer discussions and questions involving Microsoft Outlook client, your issue seems to be not related with outlook developer. Based on your description, it seems that your code is OK, and it is related with your send account? Am I right? I will suggest you test your situation manually, if it behavior the same, I assume it is related with the Outlook web application.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 10, 2015 3:18 AM