2

I'm working ics meeting invite using c#. When we send mail invite to outlook mail it automatically adds meeting invite in outlook calendar but it doesn't automatically add invite in Google Calendar until we accept the invitation by clicking on yes in gmail. I want to add meeting invite Google Calendar automatically, How can I achieve this using c#?

It works in outlook: (Here i haven't clicked on yes, still meeting invite has been added in outlook as soon as I received the email) outlook

Here's my code:

string startTime1 = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(data.START_TIME)).ToString("yyyyMMddTHHmmssZ");
string endTime1 = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(data.END_TIME)).ToString("yyyyMMddTHHmmssZ");

SmtpClient sc = SmtpSettings();
MailMessage msg = new MailMessage();

msg.From = new MailAddress("fromemail@gmail.com", "Screen Detailing");
msg.To.Add(new MailAddress(data.TO_EMAIL));              

msg.Subject = data.SUBJECT;
msg.Body = "Zoom URL: " + data.ZOOM_URL + "n/ Zoom Pwd: " + data.ZOOM_PWD; //emailbody

StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");

//PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//ABC Company//Outlook MIMEDIR//EN");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");

str.AppendLine("BEGIN:VEVENT");

str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", startTime1));
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.Now));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", endTime1));
str.AppendLine(string.Format("LOCATION: {0}", "Location"));

// UID should be unique.
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("STATUS:CONFIRMED");
str.AppendLine("BEGIN:VALARM");
str.AppendLine("TRIGGER:-PT15M");
str.AppendLine("ACTION:Accept");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");

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("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
ct.Parameters.Add("name", "meeting.ics");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
msg.AlternateViews.Add(avCal);
sc.Send(msg);

Is there any script or code which will add meeting invite automatically to any calendars on divice? i.e Googl, ios etc.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Shreyas Pednekar
  • 1,285
  • 5
  • 31
  • 53

1 Answers1

0

this it work for me.

            sb.AppendLine("BEGIN:VCALENDAR");
            sb.AppendLine("PRODID:-//app//ES");
            sb.AppendLine("BEGIN:VEVENT");
            sb.AppendLine("DTSTART:" + calendar.IcsDateStart.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
            sb.AppendLine("DTEND:" + calendar.IcsDateEnd.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
            sb.AppendLine("LOCATION:" + calendar.IcsLocation);
            sb.AppendLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + calendar.IcsDescription);
            sb.AppendLine("GEO:" + calendar.IcsLatitude + ";" + calendar.IcsLongitude + "");
            sb.AppendLine("UID:" + calendar.IcsId + "");
            sb.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", ""));
            sb.AppendLine("SUMMARY:" + calendar.IcsSummary);
            sb.AppendLine("PRIORITY:3");
            sb.AppendLine("END:VEVENT");
            sb.AppendLine("END:VCALENDAR");
            return sb;

Anyway google request always if you want go at this event.

Mario Villanueva
  • 327
  • 3
  • 10