受限于服务器不能安装outlook以及exchange,所以做了个类似于:通过SmtpClient发送Exchange会议邮件 的用smtp发送会议邮件,包含了一个用iCalendar编写的会议附件,主要代码如下:
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Host = info.host;//邮件服务器 client.Port = 25;//smtp主机上的端口号,默认是25. client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//邮件发送方式:通过网络发送到SMTP服务器 client.Credentials = new System.Net.NetworkCredential(info.username, info.psw);//凭证,发件人登录邮箱的用户名和密码 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); System.Net.Mime.ContentType calendarType = new System.Net.Mime.ContentType("text/calendar"); calendarType.Parameters.Add("name", "meeting.ics");string bodyCalendar = @"BEGIN:VCALENDAR PRODID:Microsoft CDO for Microsoft Exchange VERSION:2.0 METHOD:REQUEST X-MS-OLK-FORCEINSPECTOROPEN:TRUE BEGIN:VTIMEZONE TZID:China Standard Time BEGIN:STANDARD DTSTART:16010101T000000 TZOFFSETFROM:+0800 TZOFFSETTO:+0800 END:STANDARD END:VTIMEZONE BEGIN:VEVENT ATTENDEE;CN={10};RSVP=TRUE:{9} CLASS:PUBLIC CREATED:{8} DESCRIPTION:{6} DTEND;TZID='China Standard Time':{1} DTSTAMP:{8} DTSTART;TZID='China Standard Time':{0} LAST-MODIFIED:{8} LOCATION:{2} ORGANIZER;CN={3}:mailto:{4} PRIORITY:5 SEQUENCE:0 SUMMARY;LANGUAGE=zh-cn:Test TRANSP:OPAQUE UID:{5} X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//E N'>\n<HTML>\n<HEAD>\n<META NAME='Generator' CONTENT='MS Exchange Server ve rsion 14.02.5004.000'>\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!-- Converted f rom text/rtf format -->\n\n<P DIR=LTR ALIGN=JUSTIFY><SPAN LANG='en-us'><FO NT FACE='宋体'>{6}</FONT></SPAN><SPAN LANG='en-us'></SPAN></P></BODY></HTML> X-MICROSOFT-CDO-BUSYSTATUS:BUSY X-MICROSOFT-CDO-IMPORTANCE:1 X-MICROSOFT-DISALLOW-COUNTER:FALSE X-MS-OLK-APPTSEQTIME:{8} X-MS-OLK-AUTOFILLLOCATION:FALSE X-MS-OLK-CONFTYPE:0 BEGIN:VALARM TRIGGER:-PT15M ACTION:DISPLAY DESCRIPTION:Reminder END:VALARM END:VEVENT END:VCALENDAR"; bodyCalendar = string.Format(bodyCalendar, starttime.ToString("yyyyMMddTHHmmss"), endtime.ToString("yyyyMMddTHHmmss"), Location, info.username, info.email, Guid.NewGuid().ToString("B"), Body, Subject, DateTime.Now.ToString("yyyyMMddTHHmmssZ"), string.Join(",", attendeeList), Recipients); System.Net.Mail.AlternateView calendarView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(bodyCalendar, calendarType); calendarView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit; msg.AlternateViews.Add(calendarView); msg.From = new System.Net.Mail.MailAddress(info.email);
foreach (string attendee in attendeeList) { System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(attendee); msg.To.Add(toAddress); } msg.Subject = Subject; client.Send(msg);
发送邮件也成功,但outlook2007和2010都无法预览,附件也变成了“not supported calendar message.ics”,但双击又能正常打开。另外是否能和outlook发送会议邮件一样,直接显示的是会议页面,而不是当作附件来预览。
这就奇怪了。
VTIMEZONE的问题,定义了这个China Standard Time,附件就显示not supported calendar message.ics,去掉这个VTIMEZONE,就显示正常了。
Guid.NewGuid()
这个直接ToString()
试试。