PB中操作outlook2000
参考例子:
Int Ret
OLEObject OEAPP, Mail
OEAPP = CREATE OLEObject
Mail = CREATE OLEObject
Ret = OEAPP.ConnectToNewObject( "Outlook.Application" )
IF Ret < 0 THEN
MessageBox("连接失败!","连接到Outlook失败,请确认您的系统是否已经安装OutLook!~r~n"&
+"错误代码:"+String(Ret))
RETURN -1
END IF
Mail = OEAPP.CreateItem(0)
Mail.Subject = "标题2"
Mail.Body = "正文内容"
Mail.To = "your_email@.com" //接收者
Mail.cc = "XXX@.COM" //抄送
Mail.Attachments.add ("C:/1.DOC")
Mail.SaveAs("c:/a.msg",3) //注意,如果a.msg被其它程序打开,则会有错误
Mail.Send() //可直接将邮件发送到发件箱(好象不会马上发送出去,自己测试一下),对于outlook xp 或 outlook 2003则马上直接发送邮件
Oeapp.quit()
destroy OEAPP
destroy Mail
//说明:
Mail.SaveAs("c:/a.msg",3) 中第二个参数就是文件的类型,3->msg类型, 可以参考一下帮助文件
Mail.Send()可直接将邮件发送到发件箱(好象不会马上发送出去,自己测试一下),对于outlook xp 或 outlook 2003则马上直接发送邮件
**********************************************************************************
zt:http://www.qqday.net/program/pb/index2/53.asp
---------------------------------------------------------------------
Recently, I had to control an Outlook session from Powerbuilder application. I searched for the OLE control in the PB object browser and didn't find any controls (like OLE controls for Microsoft Word/Excel). I tried in the following way and it worked fine. It's very simple too. The following code examples explain how to use OLE automation to create, retrieve properties of Microsoft Outlook 97 mail messages, appointments and Contacts from Powerbuilder.
Listing 1
ole_outlook = Create OLEObject
//Connect to Outlook session using 'Outlook.Application'
li_return = ole_outlook.ConnectToNewObject("outlook.application")
//Check for the return code
If li_return <> 0 Then
Messagebox("Error",li_return)
Destroy ole_outlook
Return
Else
MessageBox("Success", "Connected")
End If
/* ///
Creating and Sending a New Mail Item
Create an OLEObject and connect to Outlook as shown in Listing1. Use the following code to send a mail item. The argument to the 'CreateItem' function specifies the type of item that is going to be created.
'0' Mail Item
'1' Appointment
'2' Contact
'3' Task
*/
Listing2
OLEObject ole_item, ole_attach
//Creates a new mail Item
ole_item = ole_outlook.CreateItem(0)
//Set the subject line of message
ole_item.Subject = "A new attachement for you"
//Body of mail message
ole_item.Body = "Here is a new attachment for you :"+Char(13)
//Recipient(s) Use a semicolon to separate multiple recipients
ole_item.To = "MaheshThatavarthi"
ole_attach = ole_item.Attachments
ole_attach.add(complete path of the file)
ole_item.Display //displays the message
ole_item.Send //sends the message
/* ///
Retrieving the Contents of a Folder
To access one of the default folders (such as InBox, Calendar, Sent Items, Deleted Items, and Tasks) use the 'GetDefaultFolder' function. The argument to this function specifies the folder name.
'3' DeletedItems
'5' Sent Items
'6' Inbox
'9' Calendar
'10' Contact
'13' Task
The following example shows how to list the subject and bodylines of the InBox folder Items.
Create an OLEObject and connect to Outlook as shown in Listing1.
*/
Listing 3
OLEObject ole_namespace, ole_folder
Long ll_limit
Integer li_loop
//Create the namespace object
ole_namespace = ole_outlook.GetNameSpace("MAPI")
//Argument as '6' specifies InBox folder
ole_folder = ole_namespace.GetDefaultFolder(6)
//Get the number of items in the folder
ll_limit = ole_folder.Items.Count
For li_loop = 1 To ll_limit
//Display the subject and body of the mail message
MessageBox("Subject:"+String(ole_folder.Items(li_loop).Subject), "Body:"+String(ole_folder.Items(li_loop).Body))
Next
/* ///
Adding a New Appointment
This example illustrates how you can add a new appointment to the Microsoft Outlook Calendar folder. Note the similarity between the example creating a new mailitem and this example.
Create an OLEObject and connect to Outlook as shown in Listing1.
*/
Listing 4
OLEObject ole_item
//Argument as '1' creates an appointment
ole_item = ole_outlook.CreateItem(1)
//Appointment's start time
ole_item.Start = DateTime(Today(), Now())
//Appointment's end time
ole_item.End = DateTime(Today(), RelativeTime(Now(),3600))
ole_item.Subject = "This is a test appointment"
ole_item.Location = "Meeting Hall2"
ole_item.ReminderSet = True
//Set Reminder to 15 minutes before the start of the appointment
ole_item.ReminderMinutesBeforeStart = 15
ole_item.Save //Save the appointment
/* ///
Adding a New Contact
The following example illustrates how you can add a new Contact to the MS Outlook Contacts folder. This code is also similar to the code for creating new Appointments and MailItems, as previously illustrated:
Create an OLEObject and connect to Outlook as shown in Listing1.
*/
Listing 5
//Argument as '2' creates a Contact Item
ole_item = ole_outlook.CreateItem(2)
//First Name is 'Mahesh'
ole_item.FirstName = "Mahesh"
//Last Name is 'Thatavarthi'
ole_item.LastName = "Thatavarthi"
ole_item.HomeTelephonenumber = "123-456-7890"
ole_item.HomeAddressStreet = "123 Xyz St."
//City for Home Address
ole_item.HomeAddressCity = "AnyCity"
//Postal code for the home address
ole_item.HomeAddressPostalCode = "98765"
ole_item.Save //Saves the Contact
/* ///
To retrieve the Contact information, modify the code in Listing 3 and get the properties into string variables.
NOTE: Don't forget to destroy all the valid OLEObjects and calling the 'DisConnectObject' function before closing the application. For further information refer any Outlook documentation or visit the websites http://www.wopr.com or http://www.outlookexchange.com
*/
其他资料:
http://www.microsoft.com/china/msdn/archives/library/dndotnetout2k2/html/odc_oldevsol.asp