#include <OutlookEX.au3>
#include <String.au3>
#include <IE.au3>
#include <File.au3>
#include <Array.au3>
#include <Excel.au3>
;设置outlook帐号信息
$outlookname = "我的邮箱账号"
Local $file1 = @ScriptDir & "\记录outlook发件人.txt"
Local $file2 = @ScriptDir & "\记录outlook正文.txt"
;定义邮箱信息,打开邮箱,读取邮件
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $oOutlook = _OL_Open(True, @ScriptDir & "\_OL_Warnings.exe")
If @error <> 0 Then Exit MsgBox(16, "Connect to Outlook", "Error connecting to Outlook. @error = " & @error & ", @extended = " & @extended)
;Local $oNameSpace = $oOutlook.GetNameSpace("MAPI")
;访问邮箱
Global $aFolder = _OL_FolderAccess($oOutlook, $outlookname & "\收件箱", $olFolderInbox)
;$olFolderInbox值为常量,等于6,代表收件箱
;就是此处的第二个参数不知道怎么用,运行时提示@error=4,@extended=1(下面这行的if语句结果).
If @error <> 0 Then Exit MsgBox(16, "Folder access", "Error accessing the mailbox. @error = " & @error & ", @extended = " & @extended)
;读取第一封邮件
Global $aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "", "", "", "EntryID,Subject,Body")
If @error <> 0 Then Exit MsgBox(16, "Item find", "Error searching for unread mail items. @error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aItems,"array",1)
;获取第一封邮件的发件人邮件地址
Global $aOL_Properties = _OL_ItemGet($oOutlook, $aItems[1][0], Default, "发件人")
_ArrayDisplay($aOL_Properties,"array",2)
Local $sender = $aOL_Properties[1][1]
MsgBox($MB_SYSTEMMODAL,"msg",$sender)
;正文
Local $mailbody = $aItems[1][2]
MsgBox($MB_SYSTEMMODAL,"msg",$mailbody)
;写入临时文档
If FileExists($file1) Then
Local $string = FileRead($file1)
If StringInStr($string, $sender) = 0 Then
FileWrite($file1, $sender & @CRLF)
EndIf
Else
$file = FileOpen($file1, 9)
FileWrite($file1, $sender & @CRLF)
EndIf
FileClose($file1)
If FileExists($file2) Then
Local $string2 = FileRead($file2)
If StringInStr($string2, $mailbody) = 0 Then
FileWrite($file2, $mailbody & @CRLF)
EndIf
Else
$file = FileOpen($file2, 9)
FileWrite($file2, $sender & @CRLF)
EndIf
FileClose($file2)
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
提示图片中的错误,看了帮助文档,说明中@error=4的意思是没有找到指定的文件夹(@extended=1是根目录),但是不知道怎样选择正确的文件夹(草鸟,没用过outlook,不知道怎么选择,可能是错误低级所以之前在网上搜资料也没有搜到),求帮助。