I want to send an appointment \ Meeting email (ICS) to an Outlook client. When a user receives an email, he must accept the meeting invitation and will automatically meet on the calendar, and the email will be automatically deleted.
I am using this code:
public void Sendmail_With_IcsAttachment()
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("xxxxx@xyz.com", "ABC");
msg.To.Add(new MailAddress("yyyyy@xyz.com", "BCD"));
msg.CC.Add(new MailAddress("zzzzz@xyz.com", "DEF"));
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(+330)));
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+660)));
str.AppendLine("LOCATION: " + this.Location);
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.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient();
smtpclient.Host = "localhost";
smtpclient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
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);
smtpclient.Send(msg);
}
The mail was sent correctly, but in Outlook (I test it using Outlook 2010) it shows the body, location, data, and the calendar, but above the calendar by mail I see "Unable to find the appointment on the calendar", and the "Accept", "Reject" buttons "disconnected!
I tried other solutions and found on the Internet for ex. DDAY.Ical, but I did not find any example to use it.