如何用PB操作outlook2000

ice2water 2005-12-27 09:15:09
好久没来了,最近碰到一个问题,请各位大侠帮忙。
在outlook2000(office)有多条电子邮件,用“发送”可直接发送,但是网站限制发送条数,请问如何控制outlook2000,让系统一条一条发送。
...全文
353 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwmaohui 2010-06-01
  • 打赏
  • 举报
回复
1
学习
xb8254 2006-03-09
  • 打赏
  • 举报
回复
学习
ice2water 2005-12-30
  • 打赏
  • 举报
回复
在OUTLOOK 中用宏控制发送,问题解决,谢谢大家。
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public lngend As Long

Sub ss()
lngend = 0
Do While lngend = 0
star
If lngend = 0 Then
Sleep 90000 '一分半钟
End If
Loop
End Sub


Sub star()
Dim myOlApp As Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objMAPIFolder As Outlook.MAPIFolder
Dim objMailItem As Outlook.MailItem
Dim lngMailCounter As Long
'Dim myitem As Outlook.AppointmentItem

Set myOlApp = CreateObject("Outlook.Application")
Set objNameSpace = myOlApp.GetNamespace(Type:="MAPI")
Set objMAPIFolder = _
objNameSpace.GetDefaultFolder(FolderType:=olFolderOutbox)
lngMailCounter = 1

For Each objMailItem In objMAPIFolder.Items
objMailItem.Send
lngMailCounter = lngMailCounter + 1
If lngMailCounter > 20 Then
Exit For
End If
Next objMailItem
If objMAPIFolder Is Nothing Then
lngend = 1
End If
objMAPIFolder.Display
End Sub
ice2water 2005-12-27
  • 打赏
  • 举报
回复
基本是这样,要每隔一段时间发送一次
lzheng2001 2005-12-27
  • 打赏
  • 举报
回复
没记错的话outlook2000不能用send()来发送,升级到outlook2003吧!

楼主的问题是不是由于发件箱的太多的邮件,不能一次性发出去? 可以要每隔一段时间,就发一封?
wu_07 2005-12-27
  • 打赏
  • 举报
回复
http://www.microsoft.com/china/msdn/archives/library/dndotnetout2k2/html/odc_oldevsol.asp
wu_07 2005-12-27
  • 打赏
  • 举报
回复
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

wfliu 2005-12-27
  • 打赏
  • 举报
回复
收藏学习
ice2water 2005-12-27
  • 打赏
  • 举报
回复
如当前发件箱中有多少个邮件?如何选择第一个邮件并进行发送。
ice2water 2005-12-27
  • 打赏
  • 举报
回复
lzheng2001(1加1),你说的这一步我已经做好,只是将邮件保存起来,现在是要控制让它一条一条发送。
lzheng2001 2005-12-27
  • 打赏
  • 举报
回复
参考例子:


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则马上直接发送邮件

663

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder Web 应用
社区管理员
  • Web 应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧