none
Creating Meeting Request in C#

    Question

  • Hi All,

    I am sending an email with a meeting request(calender) using C#. I also send an attachment in this email. There is two domain for sending the email in my organization. One domain is on google and second is on microsoft.

    The issue is that if i send email with attachment then meeting request does not go in the email in the microsoft domain however it goes in google.

    In microsoft domain email goes with the plain text having attachment.

    In Google, email goes with calender,text and attachment in body.

    Please find the code below I am using. Please help. Thanks in advance.


    Code:

     public static MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string summary, string location, string organizerName, string organizerEmail, MailAddressCollection attendeeList, string InterviewType, string CandidateName, string InterviewRoundType, string TelephoneNo, string timeZone, List<string> attachmentPaths)
            {
                string bodyHTML = string.Empty;
                MailMessage msg = new MailMessage();

                //  Set up the different mime types contained in the message    
                System.Net.Mime.ContentType textType = new System.Net.Mime.ContentType("text/plain");
                System.Net.Mime.ContentType HTMLType = new System.Net.Mime.ContentType("text/html");
                System.Net.Mime.ContentType calendarType = new System.Net.Mime.ContentType("text/calendar");
                //  Add parameters to the calendar header   
                calendarType.Parameters.Add("method", "REQUEST");
                calendarType.Parameters.Add("name", "meeting.ics");
                string AttendeeName = string.Empty;
                if (attendeeList != null && attendeeList.Count > 0)
                {
                    string[] ArraryAttendeeName = attendeeList[0].DisplayName.Split(' ');
                    AttendeeName = ArraryAttendeeName[0];
                }


                if (attendeeList.Count == 1)
                    bodyHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>\r\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\r\n<META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 6.5.7652.24\">\r\n<TITLE>{0}</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<!-- Converted from text/plain format -->\r\n<P><FONT SIZE=2>\r\nDear {9},\r\n<BR>\r\n<BR>Please find attached profile of {8} for {10} {12} ({7}).{11}<BR>\r\n<BR><font color='#FF0000'>This is a system generated email, do not reply to this message.</font><BR>\r\n<BR>Regards,<br>{6}\r\n<br><br></FONT>\r\n</P>\r\n\r\n</BODY>\r\n</HTML>";
                else
                    bodyHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>\r\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\r\n<META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 6.5.7652.24\">\r\n<TITLE>{0}</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<!-- Converted from text/plain format -->\r\n<P><FONT SIZE=2>\r\nDear All,\r\n<BR>\r\n<BR>Please find attached profile of {8} for {10} {12} ({7}).{11}<BR>\r\n<BR><font color='#FF0000'>This is a system generated email, do not reply to this message.</font><BR>\r\n<BR>Regards,<br>{6}\r\n<br><br></FONT>\r\n</P>\r\n\r\n</BODY>\r\n</HTML>";

                bodyHTML = string.Format(bodyHTML,
                    summary,
                    organizerName,
                    start.ToLongDateString() + " " + start.ToLongTimeString(),
                    end.ToLongDateString() + " " + end.ToLongTimeString(),
                   "Eastern Standard Time",
                    location,
                    organizerName,
                    InterviewType,
                    CandidateName,
                    AttendeeName,
                    InterviewRoundType,
                    TelephoneNo,
                    "Face To Face");
                AlternateView HTMLView = AlternateView.CreateAlternateViewFromString(bodyHTML, HTMLType);
                msg.AlternateViews.Add(HTMLView);

                //create the Body in VCALENDAR format  
                string calDateFormat = "yyyyMMddTHHmmssZ";
                string bodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US & Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN={9}:MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
                bodyCalendar = string.Format(bodyCalendar,
                    start.ToUniversalTime().ToString(calDateFormat),
                    end.ToUniversalTime().ToString(calDateFormat),
                    location,
                    organizerName,
                    organizerEmail,
                    Guid.NewGuid().ToString("B"),
                    summary,
                    subject,
                    DateTime.Now.ToUniversalTime().ToString(calDateFormat),
                    attendeeList.ToString());
                AlternateView calendarView = AlternateView.CreateAlternateViewFromString(bodyCalendar, calendarType);
                //calendarView.TransferEncoding = TransferEncoding.SevenBit;
                msg.AlternateViews.Add(calendarView);


                if ((attachmentPaths != null) && attachmentPaths.Count > 0)
                {
                    foreach (string sAttachment in attachmentPaths)
                    {
                        msg.Attachments.Add(new System.Net.Mail.Attachment(sAttachment));
                    }
                }


                //  Address the message   
                msg.From = new MailAddress(organizerEmail);
                foreach (MailAddress attendee in attendeeList)
                {
                    msg.To.Add(attendee);
                }
                msg.Subject = subject;
                return msg;
            }

    Thursday, May 2, 2013 7:49 AM

All replies