为特定用户使用 Outlook.AppointmentItem oAppointment
using Outlook.AppointmentItem oAppointment for a specific user
我已经对此进行了一些研究,但未能找到我的确切问题的示例,尽管如果我错过了很多,我深表歉意。
我有一些代码可以自动将约会添加到我的 Outlook 日历中,然后向收件人发送电子邮件。但是现在我希望能够将它添加到通用用户名上的 public 日历中...所以我使用的代码只将它添加到已登录的用户日历中。
这是按下按钮时执行此操作的代码:
private void button1_Click(object sender, EventArgs e)
{
string name = "Test Name";
DateTime startDate = new DateTime(2015, 4, 2);
DateTime endDate = new DateTime(2015, 4, 2);
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = "Enquiry Changes made to " + name + "'s enquiry"; // set the subject
oAppointment.Body = "This is where the appointment body of the appointment is written"; // set the body
oAppointment.Location = "The location"; // set the location
oAppointment.Start = Convert.ToDateTime(startDate); // Set the start date
oAppointment.End = Convert.ToDateTime(endDate); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
oAppointment.Save();
Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
// email address to send to
mailItem.To = "genericemail@provider.com";
// send
mailItem.Send();
}
感谢您能给我的任何帮助....澄清一下,我希望能够将约会添加到特定用户的日历,而不是当前登录到计算机的用户。
这里有一个 link 非常相似但也没有公认的答案:How to set an appointment to other users on outlook?
使用 Outlook Exchange API 解决了我的问题:
//This will initialize the exchange web service object
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2013);
//Setting service URL
try
{
exchangeService.AutodiscoverUrl("emailaddress@domain.co.uk");
}
catch (AutodiscoverLocalException ex)
{
//If auto discover URL fails mannualy configure the exchange service URL
exchangeService.Url = new Uri("https://yourexchangename/EWS/Exchange.asmx");
Console.WriteLine(ex.Message);
}
exchangeService.Credentials = new WebCredentials("username", "password", "domain");
//OR
exchangeService.Credentials = new NetworkCredential("username", "password", "domain");
Appointment appointment = new Appointment(exchangeService);
appointment.Subject = "Sample subject";
appointment.Body = "sample Body";
appointment.Start = new DateTime(2015, 4, 1, 8, 0, 0);
appointment.End = appointment.Start.AddHours(9.5);
// Occurs every weeks on Tuesday and Thursday
appointment.Save();
这段代码将尝试 3 种方式连接到特定用户帐户,在我的例子中,这是一个通用用户,其中保留了一个共享日历。代码的第二部分会将约会直接添加到您的日历中....希望这对人们有所帮助
很高兴我的文章对您有所帮助。
要向 public(即 chared)日历添加新的约会项目,您需要先获取共享文件夹。要完成这项工作,您需要使用命名空间 class 的 GetSharedDefaultFolder 方法,其中 returns 一个 Folder 对象代表指定用户的指定默认文件夹。例如:
Sub ResolveName()
Dim myNamespace As Outlook.NameSpace
Dim myRecipient As Outlook.Recipient
Dim CalendarFolder As Outlook.Folder
Set myNamespace = Application.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("Dan Wilson")
myRecipient.Resolve
If myRecipient.Resolved Then
Call ShowCalendar(myNamespace, myRecipient)
End If
End Sub
Sub ShowCalendar(myNamespace, myRecipient)
Dim CalendarFolder As Outlook.Folder
Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
CalendarFolder.Display
End Sub
您还可以找到命名空间 class 的 OpenSharedFolder 方法,它可以打开通过 URL 或文件名引用的共享文件夹。此方法用于访问以下共享文件夹类型:
- Webcal 日历 (webcal://mysite/mycalendar)
- RSS 提要(提要://mysite/myfeed)
- Microsoft SharePoint Foundation 文件夹 (stssync://mysite/myfolder)
- iCalendar 日历 (.ics) 文件
- vCard 联系人 (.vcf) 文件
- Outlook 邮件 (.msg) 文件
然后您可以使用 属性 项目使用 Add 方法添加新的约会项目。
作为考虑使用 EWS 的替代方法,请参阅 EWS Managed API, EWS, and web services in Exchange 了解更多信息。
我已经对此进行了一些研究,但未能找到我的确切问题的示例,尽管如果我错过了很多,我深表歉意。
我有一些代码可以自动将约会添加到我的 Outlook 日历中,然后向收件人发送电子邮件。但是现在我希望能够将它添加到通用用户名上的 public 日历中...所以我使用的代码只将它添加到已登录的用户日历中。
这是按下按钮时执行此操作的代码:
private void button1_Click(object sender, EventArgs e)
{
string name = "Test Name";
DateTime startDate = new DateTime(2015, 4, 2);
DateTime endDate = new DateTime(2015, 4, 2);
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = "Enquiry Changes made to " + name + "'s enquiry"; // set the subject
oAppointment.Body = "This is where the appointment body of the appointment is written"; // set the body
oAppointment.Location = "The location"; // set the location
oAppointment.Start = Convert.ToDateTime(startDate); // Set the start date
oAppointment.End = Convert.ToDateTime(endDate); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
oAppointment.Save();
Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
// email address to send to
mailItem.To = "genericemail@provider.com";
// send
mailItem.Send();
}
感谢您能给我的任何帮助....澄清一下,我希望能够将约会添加到特定用户的日历,而不是当前登录到计算机的用户。
这里有一个 link 非常相似但也没有公认的答案:How to set an appointment to other users on outlook?
使用 Outlook Exchange API 解决了我的问题:
//This will initialize the exchange web service object
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2013);
//Setting service URL
try
{
exchangeService.AutodiscoverUrl("emailaddress@domain.co.uk");
}
catch (AutodiscoverLocalException ex)
{
//If auto discover URL fails mannualy configure the exchange service URL
exchangeService.Url = new Uri("https://yourexchangename/EWS/Exchange.asmx");
Console.WriteLine(ex.Message);
}
exchangeService.Credentials = new WebCredentials("username", "password", "domain");
//OR
exchangeService.Credentials = new NetworkCredential("username", "password", "domain");
Appointment appointment = new Appointment(exchangeService);
appointment.Subject = "Sample subject";
appointment.Body = "sample Body";
appointment.Start = new DateTime(2015, 4, 1, 8, 0, 0);
appointment.End = appointment.Start.AddHours(9.5);
// Occurs every weeks on Tuesday and Thursday
appointment.Save();
这段代码将尝试 3 种方式连接到特定用户帐户,在我的例子中,这是一个通用用户,其中保留了一个共享日历。代码的第二部分会将约会直接添加到您的日历中....希望这对人们有所帮助
很高兴我的文章对您有所帮助。
要向 public(即 chared)日历添加新的约会项目,您需要先获取共享文件夹。要完成这项工作,您需要使用命名空间 class 的 GetSharedDefaultFolder 方法,其中 returns 一个 Folder 对象代表指定用户的指定默认文件夹。例如:
Sub ResolveName()
Dim myNamespace As Outlook.NameSpace
Dim myRecipient As Outlook.Recipient
Dim CalendarFolder As Outlook.Folder
Set myNamespace = Application.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("Dan Wilson")
myRecipient.Resolve
If myRecipient.Resolved Then
Call ShowCalendar(myNamespace, myRecipient)
End If
End Sub
Sub ShowCalendar(myNamespace, myRecipient)
Dim CalendarFolder As Outlook.Folder
Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
CalendarFolder.Display
End Sub
您还可以找到命名空间 class 的 OpenSharedFolder 方法,它可以打开通过 URL 或文件名引用的共享文件夹。此方法用于访问以下共享文件夹类型:
- Webcal 日历 (webcal://mysite/mycalendar)
- RSS 提要(提要://mysite/myfeed)
- Microsoft SharePoint Foundation 文件夹 (stssync://mysite/myfolder)
- iCalendar 日历 (.ics) 文件
- vCard 联系人 (.vcf) 文件
- Outlook 邮件 (.msg) 文件
然后您可以使用 属性 项目使用 Add 方法添加新的约会项目。
作为考虑使用 EWS 的替代方法,请参阅 EWS Managed API, EWS, and web services in Exchange 了解更多信息。