Call the APIs in Outlook from C # to initiate special messages such as meetings. The method is as follows: After you create the project, add it. NET reference: "Microsoft.Office.Interop.Outlook" reference, you can call, note that, when added, notice the Office version number.
In the process of invoking its API initiation meeting, a problem has been encountered:
After creating an appointment entry, it took a long time to find out how to specify "sender" for this appointment, and later on, in the Window CF, there was a outlooksession to find the person information,
Does Outlook have the same way, after testing, to really find a way, originally, its API specifies that the sender is directly related to the account settings of the Outlook running on your computer.
You can find the collection of accounts you set up by ApplicationClass.Session.Accounts, and you need to be particularly aware that, here, when you take an individual, the index of the collection starts at 1, not
Starting from 0. After the associated account is found, you can specify the sender of the appointment by using the Appointmentitem.sendusingaccount property.
Here is the code for the test, run it under Win2003+office12, and successfully create the meeting:
The following are the referenced contents: Using System; Using System.Collections.Generic; Using System.Text; Using Microsoft.Office.Interop.Outlook; /**///////////////////// /**//* Call the Outlook API launch meeting /* mcjeremy@cnblogs.com //////////////////// Namespace Outlookapi { Class Program { static void Main (string[] args) { Try { ApplicationClass oapp = new Microsoft.Office.Interop.Outlook.ApplicationClass (); A meeting is a kind of dating AppointmentItem oitem = (AppointmentItem) oapp.createitem (Olitemtype.olappointmentitem); Oitem.meetingstatus = olmeetingstatus.olmeeting; Oitem.subject = "Subject"; Oitem.body = "Content"; Oitem.location = "place"; Start time Oitem.start = DateTime.Now.AddDays (1); End time Oitem.end = DateTime.Now.AddDays (2); Reminder settings Oitem.reminderset = true; Oitem.reminderminutesbeforestart = 5; Whether the whole day event Oitem.alldayevent = false; Oitem.busystatus = Olbusystatus.olbusy; The index starts at 1 and not from 0 Sender's account information Oitem.sendusingaccount = oapp.session.accounts[2]; Add a required person Recipient force = OITEM.RECIPIENTS.ADD ("mailuser2@mailserver.com"); Force. Type = (int) olmeetingrecipienttype.olrequired; Add an optional person Recipient opt = OITEM.RECIPIENTS.ADD ("mailuser3@p.mailserver.com"); Opt. Type = (int) olmeetingrecipienttype.oloptional; Add Meeting Initiator Recipient sender = OItem.Recipients.Add ("mailuser1@mailserver.com"); Sender. Type = (int) Olmeetingrecipienttype.olorganizer; OItem.Recipients.ResolveAll (); Oitem.saveas ("D:/test.") MSG ", olsaveastype.olmsg); Oitem.send (); MailItem Mitem = (MailItem) oapp.createitem (Olitemtype.olmailitem); Recipient RTo = MITEM.RECIPIENTS.ADD ("* * *"); Rto.type = (int) Olmailrecipienttype.olto; Recipient Rcc=mitem.recipients.add ("* * *"); Rcc.type = (int) OLMAILRECIPIENTTYPE.OLCC; Recipient RBC = MITEM.RECIPIENTS.ADD ("* * *"); Rbc.type = (int) olmailrecipienttype.olbcc; Console.WriteLine ("OK"); } catch (System.Exception ex) { Console.WriteLine (ex. message); } Console.ReadLine (); } } } |