找回密码
 加入
搜索
查看: 3222|回复: 7

[AU3基础] au3访问outlook收件箱有问题[已解决]

[复制链接]
发表于 2016-4-14 15:32:19 | 显示全部楼层 |阅读模式
本帖最后由 失守卫 于 2016-4-18 13:14 编辑

在oulook.au3里有个_OL_FolderAccess函数,运行是老是报错,
#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,不知道怎么选择,可能是错误低级所以之前在网上搜资料也没有搜到),求帮助。
脚本还没有写完,不完善的地方请见谅,开头都运行不下去,写完后面也没意义

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2016-4-18 12:58:10 | 显示全部楼层
解决了,找到最后发现是有俩个问题,一个是邮箱的imap/开启smtp服务没有开启,另一个是outlook版本有问题
 楼主| 发表于 2016-4-18 13:11:53 | 显示全部楼层
怎么设置为已处理
发表于 2016-4-18 14:06:39 | 显示全部楼层
编辑贴子标题.   加上已解决
 楼主| 发表于 2016-4-18 15:57:50 | 显示全部楼层
回复 4# 大叔
非常感谢,已经改掉了
发表于 2019-2-25 17:25:51 | 显示全部楼层
楼主的你的outlook 是客户端的吗?我这边找到文件也出现你提示的错误,去哪里设置呢?
发表于 2019-2-25 17:44:44 | 显示全部楼层
谢谢!已经找到解决方案了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-19 11:06 , Processed in 0.086413 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表