我已成功向我需要的用户发送电子邮件会议请求。会议时间为上午8:30至上午9:00。当用户收到电子邮件和邀请时,它处于UTC时间。意思是会议时间是凌晨4:30到凌晨5:00。当我的设置为EST时,这不是和Outlook时区问题。我试图使用DateTime
和其他方法指定,但它们都不起作用。无论我是否指定,为什么总是以UTC为单位?
SmtpClient MyMail = new SmtpClient("000.000.000.00");
MyMail.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("noreply@xxxx.org", "noreply@xxxx.org");
msg.To.Add(new MailAddress("xxxx@xxxx.org", "Your Name"));
msg.Subject = "Send Calendar Appointment Email";
msg.Body = "Here is the Body Content";
StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("PRODID:-//A");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", "20170822T083000Z"));
//specifying what time zone
var timeUtc = DateTime.UtcNow;
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone);
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", easternTime));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", "20170822T090000Z"));
str.AppendLine("LOCATION: Here");
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);
MyMail.Send(msg);
答案 0 :(得分:1)
问题在于这一行:
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", "20170822T090000Z"));
从指定时间删除'z'会阻止它与时区链接。