我如何以编程方式取消使用ASP.NET VB的Outlook会议? [英] How can I programmatically cancel an outlook meeting with asp.net VB?

查看:99
本文介绍了我如何以编程方式取消使用ASP.NET VB的Outlook会议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以以编程方式创建会议请求,该会议请求通过代码发送给用户,并显示在Outlook邮件中,用户可以在其中接受请求,如果接受,约会将显示在其Outlook日历上.但在弄清楚如何以编程方式取消同一事件时遇到了麻烦.

I can programmatically create a meeting request that is sent to the user through code and appears in Outlook mail where the user can accept the request and if accepted the appointment shows on their Outlook calendar. but am having trouble figuring out how to programmatically cancel the same event.

下面的代码是我用来发送会议邀请的代码.它可以正常工作并将请求发送给收件人,他们可以接受或拒绝.如果被接受,约会将在他们的日历上进行.

The below code is what I am using to send the meeting invitation. It works as should and sends the request to the recipient and they can accept or decline. If accepted the appointment goes on their calendar.

 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日历中删除.感谢您的帮助.

The below code is what I have to CANCEL an existing meeting. It sends the notice out just like the above code does, but it does not cancel/delete/remove the meeting. Can someone point me in the right direction please. I would just like the event to be removed from the Outlook calendar when this part of the code is ran. Thanks for any help.

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)

推荐答案

ANSWERED

要取消会议并将其从Outlook日历中删除,您需要将发送取消请求的事件的方法从请求"更改为取消".

To cancel the meeting and have it removed from the outlook calendar you need to change the Method from "REQUEST" to "CANCEL" for the event that sends the cancellation request.

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.'''

这篇关于我如何以编程方式取消使用ASP.NET VB的Outlook会议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆