参考例子:
Int RetOLEObject OEAPP, Mail
OEAPP = CREATE OLEObjectMail = CREATE OLEObject
Ret = OEAPP.ConnectToNewObject( "Outlook.Application" )IF Ret < 0 THEN MessageBox("连接失败!","连接到Outlook失败,请确认您的系统是否已经安装OutLook!~r~n"& +"错误代码:"+String(Ret)) RETURN -1END 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 OEAPPdestroy 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 codeIf li_return <> 0 Then Messagebox("Error",li_return) Destroy ole_outlook ReturnElse 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 Itemole_item = ole_outlook.CreateItem(0)//Set the subject line of messageole_item.Subject = "A new attachement for you"//Body of mail messageole_item.Body = "Here is a new attachment for you :"+Char(13)//Recipient(s) Use a semicolon to separate multiple recipientsole_item.To = "MaheshThatavarthi"ole_attach = ole_item.Attachmentsole_attach.add(complete path of the file)ole_item.Display //displays the messageole_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_folderLong ll_limitInteger li_loop//Create the namespace objectole_namespace = ole_outlook.GetNameSpace("MAPI")//Argument as '6' specifies InBox folderole_folder = ole_namespace.GetDefaultFolder(6)//Get the number of items in the folderll_limit = ole_folder.Items.CountFor 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 appointmentole_item = ole_outlook.CreateItem(1)//Appointment's start timeole_item.Start = DateTime(Today(), Now())//Appointment's end timeole_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 appointmentole_item.ReminderMinutesBeforeStart = 15ole_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 Itemole_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 Addressole_item.HomeAddressCity = "AnyCity"//Postal code for the home addressole_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