VCalendar Message Body Formatting

吃可爱长大的小学妹 提交于 2020-03-04 06:29:44

问题


I need to send out an Outlook calendar appointment from a web app that I have. That is all working fine, except I cannot get the format that I want. It seems that Outlook transforms HTML to RTF and things like tables, etc dont render properly. Here is a sample of what I would like the email to look like.

– Application Production Release Details:

RFC Ticket #:        XXXXX              Project / Release Name: XXXX
Release Date:        2/22/2012          Release Time:           10:00PM 
CAB Approval Status: Approved   

Contact Information:
Project / Team Lead: XXXXXXX            On Call DSE:             XXXXX  
Phone:               XXXXXXX            Phone:                   XXXXXXX    

Migration Instructions:
Step 1: Browse to RMT Home Page: 
Step 2: Under PRODUCTION Servers Section, Select the below mentioned Deploy Dashboard
Step 3: Login using your Network Credentials 
Step 4: Press the Migrate button adjacent to the Application listed below
Step 5: Enter RFC Number and Hit Migrate 
Step 6: Wait for the e-Mail notification OR Use the Refresh Status button to check the      Migration Status on the dashboard 
Step 7: Logout

Load Balanced Environment: Repeat Steps for PROD-2 Server (Production Server are load    balanced if below entry says PROD-1 / PROD-2)   

Deploy Dashboard(s)                      Application                   
High Availability PROD-1 / PROD-2        ClaimsSupport  
High Availability PROD-1 / PROD-2        PolicySupport  
Connections                              WesternStateQQ
AgentSite PROD-1 / PROD-2                EBQ.BA

Notice how nice and neat this is? I could simply do this with HTML tables, but the rendering gets wonky everytime (most noticeably at the bottom where it shows Servers and Applications, since the fields are variable length, there is no way easily but spaces at the end). Is there a work around this issue? I am already adding an AlternateView to the MailMessage for html as well as set the IsBodyHTML to true. Here is my message code

SmtpClient sc = new SmtpClient("server");
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("email@t.com", "email@t.com");
        msg.To.Add(new MailAddress("email@t.com", "email@t.com"));
msg.Subject = release.RFCTicket + " Instructions";
        msg.Body = "Here are the migration instructions";

        StringBuilder str = new StringBuilder();
        str.AppendLine("BEGIN:VCALENDAR");
        str.AppendLine("PRODID:-//");
        str.AppendLine("VERSION:2.0");
        str.AppendLine("METHOD:REQUEST");
        str.AppendLine("BEGIN:VEVENT");
        str.AppendLine("DTSTART:" + Convert.ToDateTime(release.ReleaseDateString + " " + release.ReleaseTimeString).ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
        str.AppendLine("DTSTAMP:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
        str.AppendLine("DTEND:" + Convert.ToDateTime(release.ReleaseDateString + " " + release.ReleaseTimeString).ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));

        str.AppendLine("LOCATION: Call");
        str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
        str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
        str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
        str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
        str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));

        str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address));

        str.AppendLine("BEGIN:VALARM");
        str.AppendLine("TRIGGER:-PT15M");
        str.AppendLine("ACTION:DISPLAY");
        str.AppendLine("DESCRIPTION:Reminder");
        str.AppendLine("END:VALARM");
        str.AppendLine("END:VEVENT");
        str.AppendLine("END:VCALENDAR");
        System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
        ct.Parameters.Add("method", "REQUEST");
        AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
        msg.AlternateViews.Add(avCal);

        AlternateView body1 = AlternateView.CreateAlternateViewFromString(body, new System.Net.Mime.ContentType("text/html"));
        msg.AlternateViews.Add(body1);
        msg.IsBodyHtml = true;
        sc.Send(msg);

Any help would be appreciated. Thanks

来源:https://stackoverflow.com/questions/9335045/vcalendar-message-body-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!