0

ユーザーに送信される電子メールに calender.ics ファイルの添付ファイルを作成しました。その後、ユーザーは予定の詳細をカレンダーに追加できます (Outlook、Google カレンダー、Yahoo! などを選択します)。添付ファイルをクリックしてファイルをダウンロードすると、.ics ファイルは美しく機能しますが、「カレンダーに追加」ハイパーリンクがある適切な例や、実際に成功しない方法を無限に探しました。C#でこれを達成する方法はありますか? 何か不足していますか?これは Icalender を初めて試したときで、StringBuilder() を使用して .ICS ファイルを作成しています。

        var customerMailMessage = new MailMessage(Store.LocationEmail, CustomerEmail);
        customerMailMessage.Subject = "Appointment Request For " + ServiceDate.ToShortDateString();
        customerMailMessage.Body = body.ToString();
        customerMailMessage.IsBodyHtml = true;

        //Start of calender invite
        DateTime ServiceTime = ServiceDate.Date.Add(StartTime.TimeOfDay);
        DateTime DateStart = Convert.ToDateTime(ServiceTime);
        string DateFormat = "yyyyMMddTHHmmssZ";
        string now = DateTime.Now.ToUniversalTime().ToString(DateFormat);
        string Location = string.Format(Store.LocationAddress1 + " " + Store.LocationCity + " " + Store.LocationState + " " + Store.LocationZip);
        string Summary = "Calendar reminder";
        string Description = "Your appointment details on: " + DateStart;
        string FileName = "ServiceAppointment.ics";
        Guid guid = Guid.NewGuid();

        StringBuilder sb = new StringBuilder();
        sb.AppendLine("BEGIN:VCALENDAR");
        sb.AppendLine("VERSION:2.0");
        sb.AppendLine("PRODID:Domain.com");
        sb.AppendLine("CALSCALE:GREGORIAN");
        sb.AppendLine("METHOD:REQUEST");
        sb.AppendLine("BEGIN:VEVENT");
        sb.AppendLine("UID:" + guid);
        sb.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", retailStore.LocationEmail));
        sb.AppendLine(string.Format("ATTENDEE;CN='{0}, {1}';ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE:MAILTO:{2}", CustomerFirstName, CustomerLastName, CustomerEmail));
        sb.AppendLine("DTSTART:" + DateStart.ToUniversalTime().ToString(DateFormat));
        sb.AppendLine("DTSTAMP:" + now);
        sb.AppendLine("SUMMARY: " + Summary);
        sb.AppendLine("LOCATION: " + Location);
        sb.AppendLine("DESCRIPTION:" + Description);
        sb.AppendLine("PRIORITY:5");
        sb.AppendLine("TRANSP:OPAQUE");
        sb.AppendLine("END:VEVENT");
        sb.AppendLine("END:VCALENDAR");

        var calendarBytes = Encoding.UTF8.GetBytes(sb.ToString());
        System.IO.MemoryStream stream = new System.IO.MemoryStream(calendarBytes);
        Attachment attachment = new Attachment(stream, FileName, "text/calendar");
        customerMailMessage.Attachments.Add(attachment);

        System.Net.Mime.ContentType contype = new System.Net.Mime.ContentType("text/calendar");
        contype.Parameters.Add("method", "REQUEST");
        contype.Parameters.Add("name", "ServiceAppointment.ics");


        var emailProvider = new EmailProvider();
        emailProvider.Send(customerMailMessage, "Request Appointment - Customer - " + CreatedBySource);
4

1 に答える 1