首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用VB.Net通过Outlook从特定的人检索邮件?

如何使用VB.Net通过Outlook从特定的人检索邮件?
EN

Stack Overflow用户
提问于 2011-03-16 07:52:46
回答 2查看 2.6K关注 0票数 0

我从codeproject.com获得了以下代码:

代码语言:javascript
运行
复制
    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.Folders
    Dim Item As New Object
    Dim myItems As Outlook.Items
    Dim x As Int16

    objOL = New Outlook.Application()
    objNS = objOL.GetNamespace("MAPI")

    Dim olfolder As Outlook.MAPIFolder
    olfolder = objOL.GetNamespace("MAPI").PickFolder
    myItems = olfolder.Items

    Dim i As Integer
    For x = 1 To myItems.Count
        MessageBox.Show(myItems.Item(x).SenderName)
        MessageBox.Show(myItems.Item(x).SenderEmailAddress)
        MessageBox.Show(myItems.Item(x).Subject)
        MessageBox.Show(myItems.Item(x).Body)
        MessageBox.Show(myItems.Item(x).to)
        MessageBox.Show(myItems.Item(x).ReceivedByName)
        MessageBox.Show(myItems.Item(x).ReceivedOnBehalfOfName)
        MessageBox.Show(myItems.Item(x).ReplyRecipientNames)
        MessageBox.Show(myItems.Item(x).SentOnBehalfOfName)
        MessageBox.Show(myItems.Item(x).CC)
        MessageBox.Show(myItems.Item(x).ReceivedTime)
    Next x
    Dim Atmt As Outlook.Attachment

    For Each Atmt In Item.Attachment
        Dim filename As String = "C:\Email Attachments\" + Atmt.FileName
        Atmt.SaveAsFile(filename)
    Next Atmt

现在,我已经把默认文件夹设置为收件箱了。我想做的是扩展功能,只检索特定人的电子邮件,提取和保存他/她发送的任何附件。此外,当代码到达

Dim Atmt as Outlook.Attachment部件:在类型'Object‘上找不到公共成员’附件‘。,我需要这个函数来检索附件。我试过不同的方法,但都没有用。你能帮帮我吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-03-16 08:20:54

更新2

Dim项目作为新字典(指字符串,字符串),用于x=1到myItems.Count 'Mail,如果myItems.Item(x).SenderEmailAddress = "someone@mail.com“,那么对于每个Atmt,myItems(x).Attachment中的Outlook.Attachment

代码语言:javascript
运行
复制
            'A specific type of file
            If Atmt.FileName.Contains("hello") Then items("hello") = Atmt.FileName
            If Atmt.FileName.Contains("hello1") Then items("hello1") = Atmt.FileName
            If Atmt.FileName.Contains("hello2") Then items("hello2") = Atmt.FileName

            Dim filename As String = "C:\Email Attachments\" + Atmt.FileName
            Atmt.SaveAsFile(filename)

        Next Atmt
    End If
Next
For Each item As KeyValuePair(Of String, String) In items
    Console.WriteLine(item.Key & ":" & item.Value)
Next

试试这段代码

代码语言:javascript
运行
复制
Outlook.Attachment oAttach = myItems.Attachments[0];

在VB.Net中,这就像

代码语言:javascript
运行
复制
Dim oAttach as outlook.Attachment = myItems.Attachments(0);

希望它能帮上忙

票数 1
EN

Stack Overflow用户

发布于 2011-03-16 08:21:39

在您正在查看的代码项目示例代码中,附件位应该在循环中,因此:

代码语言:javascript
运行
复制
For x = 1 As Integer To myItems.Count
    For Each Atmt As Outlook.Attachment In myItems(x).Attachment
        Dim filename As String = "C:\Email Attachments\" + Atmt.FileName
        Atmt.SaveAsFile(filename)
    Next Atmt
Next
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5322389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档