[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1985
  • Last Modified:

How to Send a Calendar Invite from Exchange Server through ASP.Net

Hi,
     How to Send a Calendar Invite from Exchange Server through ASP.Net. Pls help me in sending a calendar invitaiton using from a Exchange Server using ASP.Net with C# as Back end coding. Pls suggest me how to do this or give me some sample code which would help me in doing this.

I have tried using Outlook Com componet and CDO Component but this is working fine on the local machine but when i deployed on the server it is throwing com exception. I have also tried by give permission to the com but still it is throughing the same error

OS on the Server is : Windows 2003
I have installed Outlook and Configured on the Server.

I there any way of using SHALLOW TRAVERSAL for sending a caledar invite.

Thanks in Advance
0
mohan21_kumar
Asked:
mohan21_kumar
  • 5
  • 4
  • 2
  • +1
1 Solution
 
mirtheilCommented:
You'll need to generate vCal files.  Take a look at http://www.codeproject.com/KB/aspnet/vcalendarfiletodownload.aspx
0
 
mohan21_kumarAuthor Commented:
But How to add the recepient List in vcs file??
0
 
mirtheilCommented:
From http://www.ietf.org/rfc/rfc2445.txt:
"Multiple attendees can be specified by including multiple "ATTENDEE"
   properties within the calendar component."
and
"The following is an example of this property used for specifying
   multiple attendees to an event:
     ORGANIZER:MAILTO:jsmith@host1.com
     ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=Henry Cabot
      :MAILTO:hcabot@host2.com
     ATTENDEE;ROLE=REQ-PARTICIPANT;DELEGATED-FROM="MAILTO:bob@host.com"
      ;PARTSTAT=ACCEPTED;CN=Jane Doe:MAILTO:jdoe@host1.com"

So you could iterate through your recipient list and add and "ATTENDEE;" entry for each recipient.  
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mohan21_kumarAuthor Commented:
Hi,
   I have written the following Code. But still i'm unable to send the multiple recepient. Pls help me where is the mistake which i have made.


private void CallingFunction()
{
 SmtpClient smtp = new SmtpClient();
            smtp.Host = "127.0.0.1";
 
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail = CreateMeetingRequest(DateTime.Now, DateTime.Now, "TEsting for ics file", "This is Summary", "This is Location", "Mohan KumarV", "mohan.kumarv@philips.com", "mohan,ravi,suganthi,kishore", "mohanv@blr.pin.philips.com,ravi.japur@philips.com,sugantha@blr.pin.philips.com,vkishore@blr.pin.philips.com");
 
            smtp.Send(mail);
}
 
public static System.Net.Mail.MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string summary,    string location, string organizerName, string organizerEmail, string attendeeName, string attendeeEmail)
        {
            MailAddressCollection col = new MailAddressCollection();
            string[] AEmail = attendeeEmail.Split(',');
            string[] AName = attendeeName.Split(',');
            for (int i = 0; i < AEmail.Length; i++)
            {
                if(AEmail[i] != "")
                    col.Add(new MailAddress(AEmail[i], AName[i]));
            }
 
            return CreateMeetingRequest(start, end, subject, summary, location, organizerName, organizerEmail, col);
        }
 
        public static System.Net.Mail.MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string summary, string location, string organizerName, string organizerEmail, MailAddressCollection attendeeList)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.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");    
            //  Create message body parts    
            //  create the Body in text format    
            string bodyText = "Type:Single Meeting\r\nOrganizer: {0}\r\nStart Time:{1}\r\nEnd Time:{2}\r\nTime Zone:{3}\r\nLocation: {4}\r\n\r\n*~*~*~*~*~*~*~*~*~*\r\n\r\n{5}";    
            bodyText = string.Format(bodyText,organizerName,start.ToLongDateString() + " " + start.ToLongTimeString(),end.ToLongDateString() + " " + end.ToLongTimeString(),System.TimeZone.CurrentTimeZone.StandardName,location,summary); 
            
            AlternateView textView = AlternateView.CreateAlternateViewFromString(bodyText, textType);  
            msg.AlternateViews.Add(textView);    
            
            //create the Body in HTML format   
            string 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>Type:Single Meeting<BR>\r\nOrganizer:{1}<BR>\r\nStart Time:{2}<BR>\r\nEnd Time:{3}<BR>\r\nTime Zone:{4}<BR>\r\nLocation:{5}<BR>\r\n<BR>\r\n*~*~*~*~*~*~*~*~*~*<BR>\r\n<BR>\r\n{6}<BR>\r\n</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(),System.TimeZone.CurrentTimeZone.StandardName,location,summary);   
            AlternateView HTMLView = AlternateView.CreateAlternateViewFromString(bodyHTML, HTMLType); 
            msg.AlternateViews.Add(HTMLView);   
            //create the Body in VCALENDAR format   
            string calDateFormat = "yyyyMMddTHHmmssZ";
            string AttendeeData = "";
 
 
            //attendeeList
 
            for (int i = 0; i < attendeeList.Count; i++)
            {
                AttendeeData = AttendeeData + "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"" + attendeeList[i].DisplayName.ToString() + "\":MAILTO:" + attendeeList[i].Address.ToString();
            }
 
            //AttendeeData = AttendeeData + "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}";
 
            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\n"+AttendeeData+"\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);   
            //  Adress the message    
            msg.From = new MailAddress(organizerEmail);    
            foreach (MailAddress attendee in attendeeList)    
            {       
                   msg.To.Add(attendee);    
            }    
            msg.Subject = subject;    
            return msg;
        }

Open in new window

0
 
mirtheilCommented:
What happens when you add multiple recipients?  Does it fail?  If so, what error?  If not, what is the behavior?
0
 
mohan21_kumarAuthor Commented:
When i try to add multiple recipient, In the Scheduling Tab of outlook it is not showing all the recipient.  I have attached the screenshot
cal.JPG
0
 
mohan21_kumarAuthor Commented:
And also i'm getting a bounce mail. Pls find the attachment of the bounced mail
mail.JPG
0
 
jmorsbachCommented:
Has this been solved?  I'm having the same issue.  Outlook appears to be ignoring the ATTENDEE specifications.
0
 
mirtheilCommented:
When I run the attached code, it works for me.  I see multiple attendees..
	private void btnVCal_Click(object sender, System.EventArgs e)
		{
        //'PARAMETERS
		string sTime = txtDate.Text + " " + txtTime.Text;
       DateTime beginDate = Convert.ToDateTime(sTime);
	   DateTime endDate = beginDate + new TimeSpan(1,0,0);
       String myLocation = txtLocation.Text;
       String mySubject =	txtTitle.Text;
       String myDescription = txtDescription.Text;
        //Initialization
       System.IO.MemoryStream mStream = new System.IO.MemoryStream();
       System.IO.StreamWriter writer = new System.IO.StreamWriter(mStream);
       writer.AutoFlush = true;
        //Header
       writer.WriteLine("BEGIN:VCALENDAR");
       writer.WriteLine("PRODID:-//Flo Inc.//FloSoft//EN");
       writer.WriteLine("BEGIN:VEVENT"); 
        //'BODY
       writer.WriteLine("DTSTART:" + beginDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
       writer.WriteLine("DTEND:" + endDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
	   writer.WriteLine("ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=User 1:MAILTO:user1@example.com");
	   writer.WriteLine("ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=User 2:MAILTO:user2@example.com");
       writer.WriteLine("LOCATION:" + myLocation);
       writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + myDescription);
       writer.WriteLine("SUMMARY:" + mySubject);
        //Footer
       writer.WriteLine("PRIORITY:3");
       writer.WriteLine("END:VEVENT");
       writer.WriteLine("END:VCALENDAR"); 
       //'MAKE IT DOWNLOADABLE
       Response.Clear();
       Response.AppendHeader("Content-Disposition", "attachment; filename=HopeRide.vcs");
       Response.AppendHeader("Content-Length", mStream.Length.ToString());
       Response.ContentType = "application/download";
       Response.BinaryWrite(mStream.ToArray());
       Response.End(); 
		}

Open in new window

0
 
jmorsbachCommented:
From your code I put together the following ics file (I picked static values for what otherwise would be set by variables).... I open the ICS file in outlook and I don't see multiple attendees... what am I missing?  =(  
BEGIN:VCALENDAR
PRODID:-//Flo Inc.//FloSoft//EN"
BEGIN:VEVENT
DTSTART:20080404T200000Z
DTEND:20080404T203000Z
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=User 1:MAILTO:user1@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=User 2:MAILTO:user2@example.com
LOCATION:Home
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:Hello World
SUMMARY:Multiple Attendee Test
PRIORITY:3
END:VEVENT
END:VCALENDAR

Open in new window

0
 
mirtheilCommented:
Taking the static values you posted and changing the email addresses to two different emails, I see the attendees correctly.  I'm using Outlook 2007.
0
 
vavjeevaCommented:
can anyone have the code for Cancelling the Request...
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now