如何以编程方式取消使用asp.net VB的Outlook会议?

时间:2015-10-30 18:29:20

标签: asp.net .net visual-studio outlook outlook-calendar

我可以通过编程方式创建通过代码发送给用户的会议请求,并显示在Outlook邮件中,用户可以接受该请求,如果接受,则会在Outlook日历上显示约会。但我无法弄清楚如何以编程方式取消同一事件。

以下代码是我用来发送会议邀请的代码。它按原样工作,并将请求发送给收件人,他们可以接受或拒绝。如果被接受,则约会在他们的日历上。

 Dim smtpServer As String = ConfigurationManager.AppSettings("MailServer").ToString()
 Dim credentials As New NetworkCredential(ConfigurationManager.AppSettings("SMTPUser").ToString(), ConfigurationManager.AppSettings("SMTPPassword").ToString())

 Dim startTime1 As String = Convert.ToDateTime("10/30/2015 11:00 AM").ToString("yyyyMMddTHHmmss")
 Dim endTime1 As String = Convert.ToDateTime("10/30/2015 01:00 PM").ToString("yyyyMMddTHHmmss")
 Dim smtp As New SmtpClient(smtpServer)
 smtp.Credentials = credentials

 Dim msg As New MailMessage()
 Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()
 Dim emailTo As String = "jd@dom.com"
 msg.From = New MailAddress(emailFrom, "Scheduling System")
 msg.[To].Add(New MailAddress(emailTo))
 msg.Subject = "JD"

 Dim strBody As New StringBuilder()
 strBody.AppendLine("Appointment Confirmation")
 strBody.AppendLine("Subject: JD")
 strBody.AppendLine("1599")
 strBody.AppendLine("Location: Exam 1")
 strBody.AppendLine("Date: 10/30/2015")
 strBody.AppendLine("Time: 11:00AM - 1:00PM")

 msg.Body = strBody.ToString()

 Dim str As New StringBuilder()
 str.AppendLine("BEGIN:VCALENDAR")

 'PRODID: identifier for the product that created the Calendar object
 str.AppendLine("PRODID:-//CARS//Outlook MIMEDIR//EN")
 str.AppendLine("VERSION:2.0")
 str.AppendLine("METHOD:REQUEST")

 str.AppendLine("BEGIN:VEVENT")

 str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmss}", startTime1))
 'TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
 str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmss}", DateTime.Now))
 str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmss}", endTime1))       
 'TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
 str.AppendLine(String.Format("LOCATION:{0}", "Exam 1"))

 ' UID should be unique.
 str.AppendLine(String.Format("UID:{0}", "jd101"))
 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("STATUS:CONFIRMED")
 str.AppendLine("BEGIN:VALARM")
 str.AppendLine("TRIGGER:-PT15M")
 str.AppendLine("ACTION:Accept")
 str.AppendLine("DESCRIPTION:Reminder")
 str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY")
 str.AppendLine("END:VALARM")
 str.AppendLine("END:VEVENT")

 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("END:VCALENDAR")
 Dim ct As New System.Net.Mime.ContentType("text/calendar")
 ct.Parameters.Add("method", "REQUEST")
 ct.Parameters.Add("name", "meeting.ics")
 Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(str.ToString(), ct)
 msg.AlternateViews.Add(avCal)
 smtp.Send(msg)

以下代码是我取消现有会议的原因。它像上面的代码一样发送通知,但它不会取消/删除/删除会议。请有人指出我正确的方向。我希望在运行此部分代码时从Outlook日历中删除该事件。谢谢你的帮助。

Dim smtpServer As String = ConfigurationManager.AppSettings("MailServer").ToString()
Dim credentials As New NetworkCredential(ConfigurationManager.AppSettings("SMTPUser").ToString(), ConfigurationManager.AppSettings("SMTPPassword").ToString())

Dim startTime1 As String = Convert.ToDateTime("10/30/2015 11:00 AM").ToString("yyyyMMddTHHmmss")
Dim endTime1 As String = Convert.ToDateTime("10/30/2015 01:00 PM").ToString("yyyyMMddTHHmmss")
Dim smtp As New SmtpClient(smtpServer)
smtp.Credentials = credentials

Dim msg As New MailMessage()
Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()
Dim emailTo As String = "jd@dom.com"
msg.From = New MailAddress(emailFrom, "Scheduling System")
msg.[To].Add(New MailAddress(emailTo))
msg.Subject = "JD"

Dim strBody As New StringBuilder()
strBody.AppendLine("Appointment Confirmation")
strBody.AppendLine("Subject: JD")
strBody.AppendLine("HRPO#: 1599")
strBody.AppendLine("Location: Exam 1")
strBody.AppendLine("Date: 10/30/2015")
strBody.AppendLine("Time: 11:00AM - 1:00PM")

msg.Body = strBody.ToString()

Dim str As New StringBuilder()
str.AppendLine("BEGIN:VCALENDAR")

'PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//CARS//Outlook MIMEDIR//EN")
str.AppendLine("VERSION:2.0")
str.AppendLine("METHOD:REQUEST")

str.AppendLine("BEGIN:VEVENT")

str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmss}", startTime1))
'TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmss}", DateTime.Now))
str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmss}", endTime1))
'TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(String.Format("LOCATION:{0}", "Exam 1"))

' UID should be unique.
str.AppendLine(String.Format("UID:{0}", "jd101"))
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("STATUS:CANCELLED")
str.AppendLine("BEGIN:VALARM")
str.AppendLine("TRIGGER:-PT15M")
str.AppendLine("ACTION:Accept")
str.AppendLine("DESCRIPTION:Reminder")
str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY")
str.AppendLine("END:VALARM")
str.AppendLine("END:VEVENT")

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("END:VCALENDAR")
Dim ct As New System.Net.Mime.ContentType("text/calendar")
ct.Parameters.Add("method", "CANCEL")
ct.Parameters.Add("name", "meeting.ics")
Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(str.ToString(), ct)
msg.AlternateViews.Add(avCal)
smtp.Send(msg)

2 个答案:

答案 0 :(得分:4)

<强> ANSWERED

要取消会议并将其从展望日历中删除,您需要更改方法&#34; REQUEST&#34;到&#34;取消&#34;对于发送取消请求的事件。

msg.Body = strBody.ToString()

Dim str As New StringBuilder()
str.AppendLine("BEGIN:VCALENDAR")

'PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//CARS//Outlook MIMEDIR//EN")
str.AppendLine("VERSION:2.0")
'''ORIGINAL-CHANGE TO CANCEL'''
'str.AppendLine("METHOD:REQUEST")
'''NEW - CHANGE TO CANCEL'''
str.AppendLine("METHOD:CANCEL")
'''Everything else remains the same. Will work and remove meeting from calendar.'''

答案 1 :(得分:0)

目前我正在使用此代码将会议发送给Outlook ..

StringBuilder OutlookBody = new StringBuilder();

string textvs = @&#34; BEGIN:VCALENDAR

PRODID: - // Microsoft Corporation // Outlook 10.0 MIMEDIR // EN

VERSION:1.0

BEGIN:VEVENT

LOCATION:&#34; +位置+ @&#34;

DTSTART:&#34; + string.Format(&#34; DTSTART:{0:yyyyMMddTHHmmssZ}&#34;,start)+ @&#34;

DTEND:&#34; + string.Format(&#34; DTEND:{0:yyyyMMddTHHmmssZ}&#34;,end)+ @&#34;

说明; ENCODING =引用打印:= &#34; + OutlookBody + @&#34; = 0D = 0A 发明内容:&#34; + AppoitmentName + @&#34;

PRIORITY:3

END:VEVENT

END:VCALENDAR&#34 ;;

它工作得很好..

如何使用相同的代码取消/删除outlook中的约会。