Click here to Skip to main content
14,693,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

Im in urgent situation to add a ms outlook calendar items via asp.net/c#, I could find a sample for this,but it works when sender and receiver are different mail address.
But my requirement is when my customer create a appointment customer's outlook calendar should disaply the appointment with reminder, so basically sender and receiver mail address are same

example - fromaddress - test@mail.com, toaddress - test@mail.com

so this scenario, im only getting Appointment mail, but not saving in a calendar.

but i when i used different mail address as sender, its work fine,

pls help me solve this issue.

Thanks

Regards,
IndSoft
Posted
Updated 26-Oct-12 1:34am
v2
Comments
[no name] 26-Oct-12 6:37am
   
What Happens when you use test1@mail.com and test2@mail.com does it save in you calender ?
slSoftware 26-Oct-12 6:49am
   
hi

thx for ur reply.

when i use same email address for sender and receiver,i just get a mail without saving into calendar.

Thx
slSoftware 26-Oct-12 6:50am
   
hi
when i use two different mail address, its working fine, saving into calendar in outlook.
[no name] 26-Oct-12 6:58am
   
pls share a code sippnet. I tried to do it manually in outlook and it worked. so problem can be
1. in your code.
2. in the outlook class.
slSoftware 26-Oct-12 7:00am
   
hi,

i have also tried it in manually in outlook, its worked for me too, issue is with when run through the code,
[no name] 26-Oct-12 7:03am
   
When i do it from outlook, i never recieves any email. Don't you feel that it is one of geature of outlook. Why would someone will send himself a appointment ? For reminders the Reminders features can be used.
slSoftware 26-Oct-12 7:09am
   
Hi
Yes im also never got mail, just with reminder, it saved into calendar, when i did it manually.

but i have tried using Microsoft.Office.Interop.Outlook.Application dll in windows application, there also used same sender and receiver same email address, but in windows it working fine.
slSoftware 26-Oct-12 7:04am
   
private void SendAppointmentMethod4()
{

System.Net.Mail.SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]);
smtp.Port = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]);

System.DateTime schBeginDate = Convert.ToDateTime("26/10/2012 13:50:00 PM").ToUniversalTime();
System.DateTime schEndDate = Convert.ToDateTime("26/10/2012 13:50:00 PM").ToUniversalTime();

smtp.Send(CreateMeetingRequest(schBeginDate, schEndDate, "SendAppointmentMethod4", "SendAppointmentMethod4", "city", "Test - ASP.NET", "test@mail.com", "test",
"test@mail.com"));
}

public MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string summary,
string location, string organizerName, string organizerEmail, string attendeeName, string attendeeEmail)
{
MailAddressCollection col = new MailAddressCollection();
col.Add(new MailAddress(attendeeEmail, attendeeName));
return CreateMeetingRequest(start, end, subject, summary, location, organizerName, organizerEmail, col);
}
slSoftware 26-Oct-12 7:07am
   
cant paste all the code here, i have put method by method

this is last mehtod

public MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string summary,
string location, string organizerName, string organizerEmail, MailAddressCollection attendeeList)
{
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");

// 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>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\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);
slSoftware 26-Oct-12 7:07am
   
//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);

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

return msg;
}

1 solution

All your code looks server side. For ASP.NET, you need to access client outlook for scheduling outlook based item. Have a look at this article and see if it helps: Import and Export Outlook Appointments (using JavaScript)[^]
   
Comments
slSoftware 30-Oct-12 0:29am
   
Hi Sandeep Mewara,

Appreciate your answer for this, but my target platform is iPad, so, is there way to accomplish this from iPad?

Thx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900