Let's say I log in to the OS with administrator account and have permissions to set appointments to other users, without sending a mail.
How can I do it in the code?
I could only find examples working with AppontmentItem and set an appointment to the local machine's outlook. How can I do it for external users?
Many thanks in advance!
private static void AddAppointment()
{
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 john enquiry"; // set the subject
oAppointment.Body = "This is where the appointment body of the appointment is written"; // set the body
oAppointment.Location = "Nicks Desk!"; // set the location
oAppointment.Start = DateTime.Now.AddHours(2);
oAppointment.End = DateTime.Now.AddHours(3);
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();
}
Use Namespace.GetSharedDefaultFolder() to open other user's Calendar folder, then create an appointment using MAPIFolder.Items.Add.
Related
I am creating a windows application in C# for setting appointments in a shared calendar for my team. I am the owner of the calendar. I have written the code to set the appointment and set reminder time as 24 hrs before the meeting. But instead of sending reminder to attendee it is sending reminder to me. I am using Microsoft.Office.Interop.Outlook for this. Here is the code that I used:
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Get the Calendar folder.
Outlook.Recipient rcip = oNS.CreateRecipient("abc#domain.com");
Outlook.MAPIFolder oSharedCal = oNS.GetSharedDefaultFolder(rcip, Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder oShiftCal = oSharedCal.Folders["Sample"];
// Get the Items (Appointments) collection from the Calendar folder.
Outlook.Items oItems = oSharedCal.Items;
Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem)oItems.Add();
// Set Appointment properties.
oAppt.Subject = Subject;
oAppt.Start = start;
oAppt.End = end;
oAppt.RequiredAttendees = email;
oAppt.ReminderMinutesBeforeStart = 24 * 60;
oAppt.ReminderSet = true;
oAppt.BusyStatus = Outlook.OlBusyStatus.olFree;
//Show the item to pause.
oAppt.Save();
oAppt.Send();
Can anyone help me with this?
Reminders cannot be set for attendees, they are for your copy of the appointment in the calendar you create it in. Attendees can set a reminder for themselves when the accept the meeting request.
I am developing a C# application that uses Outlook COM object library.
After adding the appointment to the calendar, it is immediately shown in Outlook desktop application but the appointment is not found at Outlook web application. The miserable thing is that some appointments got synchronized and it stopped synchronizing suddenly.
Here's how I saved the appointment:
Outlook.Application olApp = new Outlook.Application();
Outlook.NameSpace mapiNS = olApp.GetNamespace("MAPI");
string profile = "";
mapiNS.Logon(profile, null, null, null);
Outlook.AppointmentItem apt = olApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
apt.Save();
How can I make it get synchronized?
I had to call send method after the save method, otherwise the Outlook sends the appointment whenever it wants.
Outlook.Application olApp = new Outlook.Application();
Outlook.NameSpace mapiNS = olApp.GetNamespace("MAPI");
string profile = "";
mapiNS.Logon(profile, null, null, null);
Outlook.AppointmentItem apt = olApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
apt.Save();
apt.Send();
I have two mailboxes setup in Outlook.
I'll refer to them as "email1#mail.com" and "email2#mail.com".
I would like to use Interop to create and send an appointment to a specific email address calender, not just to the default outlook account.
using System;
using System.Diagnostics;
using System.Reflection;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace Program
{
class Program
{
public static void Main(string[] args)
{
// Create the Outlook application.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Outlook.Account account = oApp.Session.Accounts["email2#mail.com"];
// Get the NameSpace and Logon information.
Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Create a new mail item.
Microsoft.Office.Interop.Outlook.MailItem oMsg =(Microsoft.Office.Interop.Outlook.MailItem) oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = "test";
// Set HTMLBody.
oMsg.HTMLBody = "test";
oMsg.To = "test#gmail.com";
//oMsg.CC = _cc;
//oMsg.BCC = _bcc;
oMsg.Save();
oMsg.SendUsingAccount = account;
// Add a recipient.
//Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;
// TODO: Change the recipient in the next line if necessary.
//Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(_recipient);
//oRecip.Resolve();
// Send.
(oMsg as Microsoft.Office.Interop.Outlook._MailItem).Send();
// Log off.
oNS.Logoff();
// Clean up.
//oRecip = null;
//oRecips = null;
oMsg = null;
oNS = null;
oApp = null;
}
}
}
This code works flawlessly in sending an email automatically to "test#gmail.com" from my email "email2#mail.com".
However, I would like to automatically create an appointment/meeting for a specific email address.
This is my current attempt:
using System;
using System.Diagnostics;
using System.Reflection;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace SendEventToOutlook
{
class Program
{
public static void Main(string[] args)
{
try
{
// Create the Outlook application.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Outlook.Account account = oApp.Session.Accounts["email2#mail.com"];
// Get the nameSpace and logon information.
Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Create a new Appointment item.
Microsoft.Office.Interop.Outlook.AppointmentItem appt =
(Microsoft.Office.Interop.Outlook.AppointmentItem)
oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
appt.Start = DateTime.Now;
appt.End = DateTime.Now.AddDays(7);
appt.Location = "Test";
appt.Body = "Test";
appt.AllDayEvent = false;
appt.Subject = "Test";
appt.Save();
appt.SendUsingAccount = account;
// Log off.
oNS.Logoff();
appt = null;
oNS = null;
oApp = null;
}
catch (Exception ex)
{
Debug.WriteLine("The following error occurred: " + ex.Message);
}
}
}
}
This code does create an appointment successfully, but it keeps creating an appointment for "email1#mail.com" instead of "email2#mail.com", which shouldn't happen as I've specified the sending account to be "email2#mail.com" from the lines:
Outlook.Account account = oApp.Session.Accounts["email2#mail.com"];
and then
appt.SendUsingAccount = account;
This is how my two email addresses are set up in Outlook: http://i.imgur.com/0eopV8A.png
Both the email addresses have different user names and are from different domains/mail servers, as shown in that screenshot.
Would anyone be able to see the problem I'm making or if there's a different solution?
Thank you.
It is not clear whether you have got two accounts set up in the single Mail profile or separate profiles.
The SendUsingAccount property of the AppointmentItem class allows to set an Account object that represents the account under which the AppointmentItem is to be sent. So, The SendUsingAccount property can be used to specify the account that should be used to send the AppointmentItem when the Send method is called. It is not what you are looking for I suppose.
Anyway, you can use the GetDefaultFolder method of the Store class which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.
Thus, you can get the Calendar folder for the required account and add a new appointment there.
You may find the following articles in MSDN helpful:
How to: Create a Sendable Item for a Specific Account Based on the Current Folder (Outlook)
Using Multiple Accounts for the Same Profile on Outlook
Having created an outlook appointment doing something like this;
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook.AppointmentItem appt = null;
app = new Microsoft.Office.Interop.Outlook.Application();
appt = (Microsoft.Office.Interop.Outlook.AppointmentItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
appt.Subject = sub;
appt.Body = body;
appt.Location = Loc;
appt.Recipients.Add(email);
appt.Save();
appt.Send();
Outlook.MailItem mailItem = appt.ForwardAsVcal();
mailItem.To = email;
mailItem.Body = body;
mailItem.Send();
Looking for pointers, as I'm having difficulty finding a definitive answer via Google.
How do I then (at a later date..) retrieve this appointment again from one or more outlook accounts and update some details?
Or is it possible to release a new appointment that will overwrite the existing one?
If you are always accessing the appointment from the same mailbox, store the value of the AppointmentItem.EntryID property and reopen it at a later point using Namespace.GetItemfromID.
If you need to access the appointment from multiple mailboxes, read the value of the AppointmentItem.GlobalAppointmentID. Unfortunately Outlook Object Model would not let you search on a binary property (MAPIFolder.Items.Find). You would need to either drop down to the Extended MAPI level (C++ or Delphi) or use Redemption - see
http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/63ea7bda-9767-4145-8ced-78e1095a49f8/
I'm trying to implement creating/updating appointments via C# code. I'm using dedicated exchange account and webdav to communicate. Updating appointment require saving this appointment to our tech-user mailbox.
Is there any other option to create and update appointments? Right now I'm struggling limits in quantity of calendar appointment on single mailbox.
I'm sure there should be other option but I can not see it.
Looking to see if anyone else has any suggestions or solutions to this issue.
Thanks
Creating an appointment...
//Give values to Subject,body,....
_service is the Exchange service object.
Appointment app = new Appointment(_service);
app.Subject = subject;
app.Body = body;
app.Start = startTime;
app.End = endTime;
app.Location = location;
DayOfTheWeek[] days = new DayOfTheWeek[] { DayOfTheWeek.Saturday };
app.Recurrence = new Recurrence.WeeklyPattern(app.Start.Date, 1, days);
app.Recurrence.StartDate = app.Start.Date;
app.Recurrence.NumberOfOccurrences = 3;
app.Save();
If you need further information please ask...