|
'创建记录集
Sub CreateRst()
Set rstAddress = New ADODB.Recordset
With rstAddress.Fields
.Append "name", adBSTR
.Append "PrimarySmtpAddress", adBSTR
End With
rstAddress.Open
End Sub
Sub getAddress_For_ALL()
'此代码调用微软cdo 1.21 库 但可以用于所有的outlook版本 outlook2003 ,outlook2010
CreateRst
Dim objSession As MAPI.Session
Dim objAddressEntryries As MAPI.AddressEntries
Dim objAddressEntry As MAPI.AddressEntry
Dim objField As MAPI.Field
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False
Set objAddressEntryries = objSession.GetAddressList(CdoAddressListGAL).AddressEntries
Dim i As Long
' Dim v 'As Object
For i = 1 To objAddressEntryries.Count
Set objAddressEntry = objAddressEntryries.Item(i)
OutputDebugString "插件" & i & "=====================================开始"
OutputDebugString "插件 邮件名称" & objAddressEntry.Name
OutputDebugString "插件 直接取邮件地址" & objAddressEntry.Fields(972947486).Value
OutputDebugString "插件" & i & "=====================================结束"
If objAddressEntry.DisplayType = CdoDisplayType.CdoUser Or objAddressEntry.DisplayType = CdoDisplayType.CdoRemoteUser Then
rstAddress.AddNew
rstAddress(0) = objAddressEntry.Name
rstAddress(1) = objAddressEntry.Fields(972947486).Value
End If
Next
rstAddress.Update
OutputDebugString "插件 全部邮件地址总条数" & i
OutputDebugString "插件 符合条件邮件地址总条数" & rstAddress.RecordCount
End Sub
Sub getAddress_For_2010()
'此代码无需调用cdo.dll,但只支持outlook2010(系统没有安装outlook2010 编译并不会报错)
CreateRst
Dim objAddressEntries As Outlook.AddressEntries
Dim objAddressEntry As Outlook.AddressEntry
Set objAddressEntries = olApp.Session.GetGlobalAddressList.AddressEntries
Dim i As Long
For i = 1 To objAddressEntries.Count - 1
Set objAddressEntry = objAddressEntries.GetNext
If objAddressEntry.DisplayType = olUser Then
rstAddress.AddNew
rstAddress(0) = objAddressEntry.Name
rstAddress(1) = objAddressEntry.GetExchangeUser.PrimarySmtpAddress
End If
Next
rstAddress.Update
End Sub
|
|