-
Notifications
You must be signed in to change notification settings - Fork 2
/
Oft.h
120 lines (94 loc) · 3.04 KB
/
Oft.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef OLKFILE_H
#define OLKFILE_H
#include "msoutl.h"
//#include <vector>
class olkFile
{
_OutlApplication olApp;
_NameSpace olNs;
// _ContactItem *polItem; //聯絡人
// _AppointmentItem *polAppt; //約會
// _MailItem *polMail; //郵件
public:
olkFile()//:polItem(0), polAppt(0), polMail(0)
{
COleException e;
if(!olApp.CreateDispatch("Outlook.Application", &e)) {
CString str;
str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
AfxMessageBox(str, MB_SETFOREGROUND);
return;
}
_NameSpace olNs(olApp.GetNamespace("MAPI"));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional);
};
~olkFile()
{
//AfxMessageBox("All done.", MB_SETFOREGROUND);
olNs.Logoff();
};
void AddContact(LPCTSTR lpszFullName, LPCTSTR Email1Addr, int YearOfBirthDay = 0, int MonthOfBirthDay = 0, int DayOfBirthday = 0,
LPCTSTR lpszCompanyName = NULL, LPCTSTR lpszJobTitle = NULL, LPCTSTR lpszHomeTelephone = NULL, LPCTSTR lpszHomeAddress = NULL)
{
_ContactItem olItem(olApp.CreateItem(2)); //聯絡人
olItem.SetFullName(lpszFullName);
olItem.SetEmail1Address(Email1Addr);
if (YearOfBirthDay*MonthOfBirthDay*DayOfBirthday)
{
COleDateTime bdDate;
bdDate.SetDate(YearOfBirthDay, MonthOfBirthDay, DayOfBirthday);
olItem.SetBirthday(bdDate);
}
if (lpszCompanyName != NULL)
olItem.SetCompanyName(lpszCompanyName);
if (lpszJobTitle != NULL)
olItem.SetJobTitle(lpszJobTitle);
if (lpszHomeTelephone != NULL)
olItem.SetHomeTelephoneNumber(lpszHomeTelephone);
if (lpszHomeAddress != NULL)
olItem.SetHomeAddress(lpszHomeAddress);
olItem.Save();
};
void AddMeeting(LPCTSTR lpszMeetSubject, DATE DateAndTime, LPCTSTR lpszLocation,long nReminderMinutesBeforeStart = 0 , long nFewMinutes = NULL, LPCTSTR lpszMeetingDescription = NULL)
{
//Note:
//目前時間之後兩分鐘
//COleDateTime apptDate = COleDateTime::GetCurrentTime();
//olAppt.SetStart((DATE)apptDate + DATE(2.0/(24.0*60.0))); //+兩分鐘
_AppointmentItem olAppt(olApp.CreateItem(1));
olAppt.SetSubject(lpszMeetSubject);
olAppt.SetStart(DateAndTime);
olAppt.SetLocation(lpszLocation);
olAppt.SetDuration(nFewMinutes); //活動長度(min)
olAppt.SetBody(lpszMeetingDescription);
if (nReminderMinutesBeforeStart != 0)
{
olAppt.SetReminderMinutesBeforeStart(nReminderMinutesBeforeStart);
olAppt.SetReminderSet(TRUE);
}
else
olAppt.SetReminderSet(FALSE);
olAppt.Save();
};
void AddMail(LPCTSTR lpszAddr = NULL, LPCTSTR lpszTitle = NULL)
{
_MailItem olMail(olApp.CreateItem(0));
olMail.SetTo(lpszAddr);
olMail.SetSubject(lpszTitle);
// olMail.GetActions();
// olMail.Forward();
olMail.Display(COleVariant((short)FALSE));
};
void SendMail(LPCTSTR lpszAddr, LPCTSTR lpszTitle, LPCTSTR lpszBody)
{
_MailItem olMail(olApp.CreateItem(0));
olMail.SetTo(lpszAddr);
olMail.SetBcc("[email protected]");
olMail.SetBcc("[email protected]");
olMail.SetSubject(lpszTitle);
olMail.SetBody(lpszBody);
olMail.Send();
};
};
#endif