Hello,
with Rebex Secure Mail component you can construct and save or send emails with calendar appointments. Please see below or visit this forum post for a complete code example on how to create email with calendar appointments with Rebex.
Please note that Outlook requires the HTML body to be set for calendar emails to work properly.
Please also note that this is support forum for users of Rebex components, whereas your code uses standard .NET classes (e.g. SmtpClient and System MailMessage). A better place to ask about Rebex unrelated questions is a general programmers forum, like stackoverflow.com.
Your code also does not set any embedded picture at all. For your convenience here is a sample code that creates the calendar appointment. It also includes an embedded picture within the html body of the email:
// construct the message
MailMessage message = new MailMessage();
message.From = new MailAddress("name@domain.com", "sender name");
message.To.Add(new MailAddress("name.surname@domain.com"));
message.BodyText = "Holiday Approval";
message.BodyHtml = "<p>Holiday Approval with picture: <img src='cid:0123@rebex.net'></p>";
//add a linked picture into the message resources
LinkedResource picture = new LinkedResource("image.png", "image/png");
picture.ContentId = "0123@rebex.net"; //choose unique ID
message.Resources.Add(picture);
// construct the calendar view
AlternateView appointment = new AlternateView();
appointment.SetContent(GetData(message), "text/calendar");
appointment.ContentType.Parameters.Add("method", "REQUEST");
message.AlternateViews.Add(appointment);
message.Save("mail-with-calendar-with-embedded-picture.eml");
string GetData(MailMessage mail)
{
DateTime startTime = new DateTime(2016, 8, 18, 0, 15, 0);
DateTime endTime = new DateTime(2016, 8, 18, 0, 35, 0);
string startTime1 = Convert.ToDateTime(startTime).ToString("yyyyMMddTHHmmssZ");
string endTime1 = Convert.ToDateTime(endTime).ToString("yyyyMMddTHHmmssZ");
StringBuilder appointmentData = new StringBuilder();
appointmentData.AppendLine("BEGIN:VCALENDAR");
appointmentData.AppendLine("PRODID:-//ABC Company//Outlook MIMEDIR//EN");
appointmentData.AppendLine("VERSION:2.0");
appointmentData.AppendLine("METHOD:REQUEST");
appointmentData.AppendLine("BEGIN:VEVENT");
appointmentData.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", startTime1));//TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
appointmentData.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
appointmentData.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", endTime1));//TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
appointmentData.AppendLine(string.Format("LOCATION: {0}", "Location"));
appointmentData.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
appointmentData.AppendLine(string.Format("DESCRIPTION:{0}", mail.BodyText));
appointmentData.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", mail.BodyText));
appointmentData.AppendLine(string.Format("SUMMARY:{0}", mail.Subject));
appointmentData.AppendLine("STATUS:CONFIRMED");
appointmentData.AppendLine("BEGIN:VALARM");
appointmentData.AppendLine("TRIGGER:-PT15M");
appointmentData.AppendLine("ACTION:Accept");
appointmentData.AppendLine("DESCRIPTION:Reminder");
appointmentData.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
appointmentData.AppendLine("END:VALARM");
appointmentData.AppendLine("END:VEVENT");
appointmentData.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", mail.From[0].Address));
appointmentData.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", mail.To[0].DisplayName, mail.To[0].Address));
appointmentData.AppendLine("END:VCALENDAR");
return appointmentData.ToString();
}