Is it possible to directly open the Outlook meeting window? - c#

I am trying to have my application to open the Outlook meeting window with some pre-populated fields.
I have found that this question was already asked here.
However, the code provided in the answer(which works fine) doesn't open the meeting window but the appointement window. Those are two different things that are handled differently in Outlook and what I need is indeed the meeting window.
Is there any way to achieve this or do I absolutely have to open the appointement window first and then invite people to turn it into a meeting?

Create an appointment just as in the other question, but then set the MeetingStatus property of the appointment.
Microsoft.Office.Interop.Outlook.Application outlookApplication = new Microsoft.Office.Interop.Outlook.Application(); ;
Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
// This line was added
appointmentItem.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
appointmentItem.Subject = "Meeting Subject";
appointmentItem.Body = "The body of the meeting";
appointmentItem.Location = "Room #1";
appointmentItem.Start = DateTime.Now;
appointmentItem.Recipients.Add("test#test.com");
appointmentItem.End = DateTime.Now.AddHours(1);
appointmentItem.ReminderSet = true;
appointmentItem.ReminderMinutesBeforeStart = 15;
appointmentItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
appointmentItem.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
appointmentItem.Recipients.ResolveAll();
appointmentItem.Display(true);

One more note to NineBerries good solution, because I had an issue here:
The line
appointmentItem.Recipients.ResolveAll();
is necessary if you have optional attendees in the meeting.
Otherwise they will be reset to "required" even if you set
recipient.Type = Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olOptional;
before, which is due to "late auto-resolving" of names in Outlook (or so it seems).

Related

Moving Mail to Outlook Sent Folder. Mail is still editable

I am editing an email and send it to the recipient. But i also want to save the original mail in the sent folder. But if i move the mailobject to the folder the mail is still editable.
This is how i move the mail:
private void CopyMailToSent(Outlook.MailItem originalMail)
{
var folder = originalMail.SaveSentMessageFolder;
originalMail.Move(folder);
}
Can i set the mailobject to readonly or faking the send?
Firstly, Outlook Object Model would not let you set the MailItem.Sent property at all. On the MAPI level, the MSGFLAG_UNSENT bit in the PR_MESSAGE_FLAGS property can only be set before the message is saved for the very first time.
The only OOM workaround I am aware of is to create a post item (it is created in the sent state), set its message class to "IPM.Note", save it, release it, reopen by the entry id (it will be now MailItem in the sent state), reset the icon using PropertyAccessor, set some sender properties (OOM won't let you set all of them).
If using Redemption (I am its author) is an option, it will let you set the Sent property as well as the sender related properties, plus add recipients without having to resolve them.
Set MySession = CreateObject("Redemption.RDOSession")
MySession.MAPIOBJECT = Application.Session.MAPIOBJECT
Set folder = MySession.GetDefaultFolder(olFolderSentMail)
Set msg = folder.Items.Add("IPM.Note")
msg.Sent = True
msg.Recipients.AddEx "Joe The User", "joe#domain.demo", "SMTP", olTo
msg.Sender = MySession.CurrentUser
msg.SentOnBehalfOf = MySession.CurrentUser
msg.subject = "Test sent message"
msg.Body = "test body"
msg.UnRead = false
msg.SentOn = Now
msg.ReceivedTime = Now
msg.Save
I couldn't solve the problem but i did workaround which works fine for me.
I hope it's ok to post this here even it's not right the solution. If not, sorry i will delete it.
My workaround is saving the orignal mail as ".msg" file and then add it to the mail in the sent folder.
Then it looks like this:
This is the code:
private void SendMail(Outlook.Mailitem mail)
{
mail.SaveAs(tempDirectory + #"originalMail.msg");
var folder = mail.SaveSentMessageFolder;
ChangeMailSubject(mail);
ChangeMailText(mail);
mail.Send();
folder.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler((sender) => AttachOriginalMail(sender);
}
private void AttachOriginalMail(object sender)
{
var mail = (Outlook.MailItem) sender;
mail.Attachments.Add(tempDirectory + #"originalMail.msg");
mail.Save();
}

Creating appointment on Exchange server calendar as other user without impersonation (EWS)

I am creating simple app for appointments scheduling and I want to implement ability for me to create appointments for my users.
I managed to create,update and delete my calendar on Exchange Server, and I somewhat managed to create appointments adding my colleagues as RequiredAttendees like so:
//service variable is being created using my credidentals
Appointment meeting = new Appointment(service);
meeting.Subject = "Some subject ";
meeting.Body = "Some body.";
meeting.Start = DateTime.Now;
meeting.End = meeting.Start.AddHours(4);
meeting.Location = "Some Location";
meeting.RequiredAttendees.Add("myCollegue#mail.com");
meeting.ReminderMinutesBeforeStart = 60;
meeting.Save(new FolderId(WellKnownFolderName.Calendar,
"myCollegue#mail.com"),
SendInvitationsMode.SendToAllAndSaveCopy);
But it is just setting him as required attendee. Next thing is I tried using impersonation, but I can't access hosting server to set myself as master and others to have to share calendar with me (due to permissions and stuff) so I had to scrape that as well. Also, he set me up to be his publishing author on his calendar.
Is there something I am missing, or can't seem to find on MSDN sites?
EDIT: I am able to create appointment in his calendar in outlok.
If anyone comes across same issues as I did in here please follow these steps:
Make sure that person for which you are creating appointment sets you up (on exchange server or in outlok as "Editing author" with all permissions.
After that you can create appointments for him (verify this by going to your outlok and creating some test appointments).
This code works for me:
Folder inboxFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "your.colleague#company.com"));
Appointment appointmentOther = new Appointment(service);
appointmentOther.Subject = "Test 2";
appointmentOther.Body = "Body text";
appointmentOther.Start = DateTime.Now;
appointmentOther.End = DateTime.Today.AddHours(16);
appointmentOther.Location = "My Office";
appointmentOther.IsReminderSet = true;
appointmentOther.ReminderMinutesBeforeStart = 30;
appointmentOther.Save(inboxFolder.Id,SendInvitationsMode.SendToNone);
Good luck :)

Open Contact Card Viewer/Editor from Outlook button

I created a custom ribbon for Microsoft Outlook and I have a button called view profile. I want to be able to bring up the Contact Card Viewer/Editor for the current user. I created a call back and I think I have the general idea of how to get his done but I am having trouble making the connection once I find the current user to getting it to open for that user. Here is the code I have so far for the call back.
public void button2_Click(Office.IRibbonControl control)
{
var appOutlook = new Microsoft.Office.Interop.Outlook.Application();
Outlook.ExchangeUser currentUser = appOutlook.Session.CurrentUser.AddressEntry.GetExchangeUser();
ContactItem contactinfo = currentUser;
contactinfo.ShowBusinessCardEditor();
}
You can use the ContactCard.
Here is C# code converted from the VBA example on this page https://msdn.microsoft.com/en-us/library/office/ff869218.aspx
var session = appOutlook.Session;
var adr = session.CurrentUser.AddressEntry;
var cc = session.CreateContactCard(adr);
cc.Show(MsoContactCardStyle.msoContactCardFull, 100, 100, 100, 100, 100, true);
The easiest way is just calling the .Display(modal: true / false) method on the ContactItem.
ContactItem contact = ...
contact.Display(true); // for modal
Simply call AddressEntry.Details:
Outlook.AddressEntry currentUser = appOutlook.Session.CurrentUser.AddressEntry;
currentUser.Details();

Adding appointment to Outlook (2013) opens up the meeting editor

I am trying to add appointments to Outlook programmatically.
I ran this code which runs successful but after I save the appointment the meeting editor opens up in outlook.
AppointmentItem appItem = null;
try
{
appItem = outlookItems.Add(OlItemType.olAppointmentItem) as AppointmentItem;
if(appItem == null)
continue;
appItem.Subject = "Subject";
appItem.MeetingStatus = OlMeetingStatus.olMeeting;
appItem.Location = "Location";
appItem.Save();
appItem.Display(true);
}
finally
{
if (appItem != null)
{
Marshal.ReleaseComObject(appItem);
}
}
I tried calling Display(true), Display(false) it still doesn't work.
Please can anyone tell me if I am doing anything wrong.
But you create a new meeting item in the code setting the following property:
appItem.MeetingStatus = OlMeetingStatus.olMeeting;
If you don't want to see a new item window (inspector), there is no need to run the following line of code:
appItem.Display(true);
The Display method displays a new Inspector object for the item.
You may find the Getting Started with VBA in Outlook 2010 article in MSDN helpful.
if the appointment is of type OlMeetingStatus.olMeeting, recipients are supposed to be present.
I changed the type to
appItem.MeetingStatus = OlMeetingStatus.olNonMeeting
and removed the call to display. I was able to save the appointment in the calendar

Appointment.Save and Appointment.Update always set IsMeeting to true

I want to create appointments, not meetings:
Appointment app = new Appointment(ews);
app.Start = DateTime.Now;
app.End = DateTime.Now.AddMinutes(60);
app.Subject = "My Subject";
app.Save();
string unid = app.Id.UniqueId;
// here the unid is given to the client, that may make another call leading to:
ItemId iid = new ItemId(unid);
app = Appointment.Bind(ews, iid, calendarFullEntryProperties);
return app.IsMeeting; // Will return true, although I never added any participants.
Why is that? Did I overlook anything in the docs?
EWS uses the same object type for meetings and appointments. The default behavior when you Save() or Update() an appointment is to send meeting invitations even if you haven't invited anyone. This essentially sets the IsMeeting to true. To save this as an appointment, change your line of code for saving to this:
app.Save(SendInvitationsMode.SendToNone);
This will keep invitations from being sent and keep IsMeeting set to false.

Categories