我要求使用html正文Tag发送会议请求。我已成功发送会议请求,它可以正常工作。
这是ICS文件格式
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
我发现了一些链接,可以通过X-ALT-DESC选项发送html链接,但它对我不起作用
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
以下是使用ICS文件发送电子邮件的C#代码
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);
这是调试器响应
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//A//B//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER;CN="Organizer":mailto:admin@wordflow.info
ATTENDEE;CN="Attendee";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=
NEEDS-ACTION;RSVP=TRUE:mailto:anandjaisy@gmail.com
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
发送邀请但是主体未发送
答案 0 :(得分:1)
我在此链接(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
找到了解决方案基本上,您添加第二个AlternateView。以下是我的表现。我的身体&#34;字符串有我的HTML。我确实注意到如果我添加&#34; avCalendar&#34;我的会议在Outlook中被破坏了。之前&#34; avHtmlBody&#34;。所以我猜这个命令很重要。
在我的meetingRequestString中,我删除了DESCRIPTION和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);