关于ical.net的两个问题

时间:2016-12-23 11:33:35

标签: c# email-attachments alternateview ical-dotnet

我需要向网络应用程序的用户发送提醒。

为此,我使用nuget包中的iCal.Net。按照使用说明,我可以发送包含ics文件附件的电子邮件。

我的第一个问题是:是否可以将邮件作为约会而不是附件发送,以便用户可以避免打开它然后保存日期?

第二:是否可以将事件描述格式化为html并使其在Outlook Office客户端和Chrome日历上运行?在这些客户端上,我看到包含所有html标签的纯文本表示。我在Windows 10日历上也进行了测试,其中事件描述正确显示为html。 我还需要设置更多内容吗?

这是我的日历字符串生成

var now = DateTime.Now;
var later = scadenza.Value;

var e = new Event
{
    DtStart = new CalDateTime(later),
    DtEnd = new CalDateTime(later),
    Description = mailText,
    IsAllDay = true,
    Created = new CalDateTime(DateTime.Now),
    Summary = $"Reminder for XYZ",

};

var attendee = new Attendee
{
    CommonName = "…..",
    Rsvp = true,
    Value = new Uri("mailto:" + ConfigurationManager.AppSettings["ReminderReceiver"])
};
e.Attendees = new List<IAttendee> { attendee };


var calendar = new Calendar();
calendar.Events.Add(e);

var serializer = new CalendarSerializer(new SerializationContext());
var icalString = serializer.SerializeToString(calendar);

这是发送提醒;请注意,如果我没有&#34;附上&#34; ics,替代观点似乎无效。

var message = new MailMessage();
message.To.Add(new MailAddress(receiverRecipient));
message.From = new MailAddress(senderRecipient);
message.Subject = messageTitle;
message.Body = "The attachment contains the reminder";
message.IsBodyHtml = true;
var smtpClient = new SmtpClient(ConfigurationManager.AppSettings["SmtpSrv"], Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]));
var cred = new NetworkCredential(ConfigurationManager.AppSettings["SmtpUser"], ConfigurationManager.AppSettings["SmtpPwd"]);
smtpClient.Credentials = cred;

System.Net.Mime.ContentType contype = new System.Net.Mime.ContentType("text/calendar");
contype.Parameters.Add("method", "REQUEST");
contype.Parameters.Add("name", "Scadenza.ics");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(icalString, contype);

message.AlternateViews.Add(avCal);

message.Attachments.Add(new Attachment(GenerateStreamFromString(icalString), contype));

smtpClient.Send(message);

0 个答案:

没有答案