3

I have a requirement to send the meeting request with html body Tag.I have successfully send the meeting request it work perfectly.

Here is the ICS file format

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//A//B//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER;CN="Organizer":mailto:#FROM#
ATTENDEE;CN="Attendee";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=
 NEEDS-ACTION;RSVP=TRUE:mailto:#TO#
DTSTART:#DTSTART#
DTEND:#DTEND#
LOCATION:#LOCATION#
SUMMARY: Invitation for Meeting
TRANSP:OPAQUE
SEQUENCE:0
UID:#UID#
DTSTAMP:#CREATED-AT#
CREATED:#CREATED-AT#
LAST-MODIFIED:#CREATED-AT#
DESCRIPTION: #DESCRIPTION#
X-ALT-DESC;FMTTYPE=text/html: #X-ALT-DESC#
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR

I found some link to send the html link wiht X-ALT-DESC option but it not work for me

Send an Outlook Meeting Request with C#

Send an Outlook Meeting Request with C#

Send email to Outlook with ics meeting appointment

Send email to Outlook with ics meeting appointment

Here is the C# code to send the email with ICS file

filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "Email/calenderInvitation.ics");
                fileContent = System.IO.File.OpenText(filePath).ReadToEnd();
                fileContent = fileContent.Replace("#TO#", receiver);
                fileContent = fileContent.Replace("#FROM#", fromAddress.Address);
                fileContent = fileContent.Replace("#LOCATION#", eventVenue);
                fileContent = fileContent.Replace("#UID#", Guid.NewGuid().ToString().Replace("-", ""));
                fileContent = fileContent.Replace("#CREATED-AT#", Convert.ToDateTime(meetingDate).ToString(TimeFormat));
                fileContent = fileContent.Replace("#DTSTART#", Convert.ToDateTime(startTime).ToString(TimeFormat));
                fileContent = fileContent.Replace("#DTEND#", Convert.ToDateTime(finishTime).ToString(TimeFormat));
                filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "Email/InvitationEmail.html");
                fileInviationContent = System.IO.File.OpenText(filePath).ReadToEnd();
                String body = AppendRedirectURl(fileInviationContent, callBackUrl);
                fileContent = fileContent.Replace("#X-ALT-DESC#", body);
                MailMessage message = new MailMessage();
               // message.IsBodyHtml = true;
                message.From = new MailAddress(fromAddress.Address);
                message.To.Add(new MailAddress(receiver));
                message.Subject = string.Format("{0}  {1} @ {2} {3} {4} {5} - {6}", "Invitation: ", meetingTypeName,
                    Convert.ToDateTime(meetingDate).ToString("dddd"), Convert.ToDateTime(startTime).ToString("MMMM"),
                    Convert.ToDateTime(startTime).ToString("yyyy"), startTime,
                    finishTime);

                var iCalendarContentType = new ContentType("text/calendar; method=REQUEST");
                var calendarView = AlternateView.CreateAlternateViewFromString(fileContent, iCalendarContentType);
                calendarView.TransferEncoding = TransferEncoding.SevenBit;
                message.AlternateViews.Add(calendarView);
                await smtp.SendMailAsync(message);

Here is the Debugger response

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//A//B//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER;CN="Organizer":mailto:[email protected]
ATTENDEE;CN="Attendee";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=
 NEEDS-ACTION;RSVP=TRUE:mailto:[email protected]
DTSTART:20171206T081500Z
DTEND:20171206T090000Z
LOCATION:asdasd
SUMMARY: Invitation for Meeting
TRANSP:OPAQUE
SEQUENCE:0
UID:b17f15326c5343ff98d76bf6092ed2b4
DTSTAMP:20171212T000000Z
CREATED:20171212T000000Z
LAST-MODIFIED:20171212T000000Z
DESCRIPTION: #DESCRIPTION#
X-ALT-DESC;FMTTYPE=text/html: <html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
    <br><br><br>
    <form class="container">
        <div class="form-group">
            <label>Click on  Accept or Decline to add event to your Email Calender </label>
        </div>
        <div class="form-group">
            <label>Will you Attend the Meeting</label>
            <a href="https://localhost:44380/Meetings/GotMeetingConfirm?userId=08c5bb4f-f4f8-4183-a99a-e82544970dd4&meetingId=6c9747e2-aeb9-4d27-8db6-077ee1d9cee9&resposne=True" id="YesConfirmMeeting" class="btn btn-primary">Yes</a>
            <a href="https://localhost:44380/Meetings/GotMeetingConfirm?userId=08c5bb4f-f4f8-4183-a99a-e82544970dd4&meetingId=6c9747e2-aeb9-4d27-8db6-077ee1d9cee9&resposne=False" id="NoConfirmMeeting" class="btn btn-danger">No</a>
        </div>
        <div class="form-group text-center">

        </div>
    </form>


</body>
</html>
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR

It send the invitation but body is not been send

1 Answer 1

5

I found the solution at this link (visual basic) https://social.msdn.microsoft.com/Forums/en-US/2cd0dcff-7d6c-493e-bf49-87a3e3248d01/create-meeting-request-with-html-body-in-aspnet?forum=netfxnetcom

Basically, you add a second AlternateView. Below is how I did it. My "body" string has my html. I did notice that my meeting was broken in Outlook if I add "avCalendar" before "avHtmlBody". So I guess the order matters.

In my meetingRequestString, I removed the parts for DESCRIPTION and X-ALT-DESC.

MailMessage msg = new MailMessage(from, to);

var htmlContentType = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Html);
var avHtmlBody = AlternateView.CreateAlternateViewFromString(body, htmlContentType);
msg.AlternateViews.Add(avHtmlBody);

string meetingRequestString = GetMeetingRequestString(from, to, subject, body, startTime, endTime);
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
ct.Parameters.Add("name", "meeting.ics");
AlternateView avCalendar = AlternateView.CreateAlternateViewFromString(meetingRequestString, ct);
msg.AlternateViews.Add(avCalendar);
client.Send(msg);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.