C # Call the outlook API to initiate a meeting

Source: Internet
Author: User

In my previous blog post, I mentioned that SharePoint calls the email server and address in the outgoing email to send emails.

However, the method can only be used to send normal emails. If you want to initiate special emails such as meetings, you can use Outlook APIs.

After creating a project, add it. net reference: "Microsoft. office. interOP. outlook "reference, you can call it, note that when adding, pay attention to the office version number.

A problem occurred while calling its API to initiate a meeting:

After creating an appointment, I have not found how to specify a sender for this appointment for a long time. Later I thought that in window CF, The lookup personnel information had an outlooksession,

Will outlook be in the same way? After testing, I found the method. Originally, the sender specified by its API was directly related to the account settings of outlook running on your machine.
You can use applicationclass. session. Accounts to find the set of accounts you set. Note that the index of the set starts from 1 when a person is retrieved.
Starts from 0. After finding the relevant account, you can use the appointmentitem. sendusingaccount attribute to specify the sender of the appointment.
--- However, if I do not use the account set in outlook, but want to specify other email accounts to send emails, what should I do? No way has been found or found up till now, and people who want to know can
Give me some advice and thank you ~~~~

Below is the testCode, Run in win2003 + office12, and the meeting is successfully created:

1 Using System;
2 Using System. Collections. Generic;
3 Using System. text;
4 Using Microsoft. Office. InterOP. outlook;
5 /**/ ////////////////////
6 /**/ /* Call outlook API to initiate a meeting
7 /* Mcjeremy@cnblogs.com
8 ////////////////////
9 Namespace outlookapi
10 {
11 Class Program
12 {
13 Static void main (string [] ARGs)
14 {
15 Try
16 {
17 Applicationclass oapp = new Microsoft. Office. InterOP. Outlook. applicationclass ();
18
19 // Meeting is a type of appointment.
20 Appointmentitem oitem = (appointmentitem) oapp. createitem (olitemtype. olappointmentitem );
21 Oitem. meetingstatus = olmeetingstatus. olmeeting;
22
23 Oitem. Subject = "topic ";
24
25 Oitem. Body = "content ";
26
27 Oitem. Location = "location ";
28
29 // Start time
30 Oitem. Start = datetime. Now. adddays (1 );
31
32 // End Time
33 Oitem. End = datetime. Now. adddays (2 );
34
35 // Reminder settings
36 Oitem. reminderset = true;
37 Oitem. reminderminutesbeforestart = 5;
38
39 // Whether it is a full-day event
40 Oitem. alldayevent = false;
41
42 Oitem. busystatus = olbusystatus. olbusy;
43
44 // Index starts from 1 instead of 0
45 // Sender's account information
46 Oitem. sendusingaccount = oapp. session. Accounts [2];
47
48 // Add a required person
49 Recipient force = oitem. Recipients. Add ("mailuser2@mailserver.com ");
50 Force. type = (INT) olmeetingrecipienttype. olrequired;
51 // Add optional persons
52 Recipient opt = oitem. Recipients. Add ("mailuser3@p.mailserver.com ");
53 Opt. type = (INT) olmeetingrecipienttype. oloptional;
54 // Add the meeting Initiator
55 Recipient sender = oitem. Recipients. Add ("mailuser1@mailserver.com ");
56 Sender. type = (INT) olmeetingrecipienttype. olorganizer;
57
58 Oitem. Recipients. resolveall ();
59
60 // Oitem. saveas ("D:/test. MSG", olsaveastype. olmsg );
61
62 Oitem. Send ();
63
64 // Mailitem mitem = (mailitem) oapp. createitem (olitemtype. olmailitem );
65 // Recipient RTO = mitem. Recipients. Add ("****");
66 // RTO. type = (INT) olmailrecipienttype. olto;
67 // Recipient RCC = mitem. Recipients. Add ("****");
68 // RCC. type = (INT) olmailrecipienttype. OLCC;
69 // Recipient rb= mitem. Recipients. Add ("****");
70 // RBC. type = (INT) olmailrecipienttype. olbcc;
71
72 Console. writeline ("OK ");
73 }
74 Catch (system. Exception ex)
75 {
76 Console. writeline (ex. Message );
77 }
78
79 Console. Readline ();
80 }
81 }
82 }
83

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.