我从codeproject.com获得了以下代码:
    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‘上找不到公共成员’附件‘。,我需要这个函数来检索附件。我试过不同的方法,但都没有用。你能帮帮我吗?
发布于 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
            '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试试这段代码
Outlook.Attachment oAttach = myItems.Attachments[0];在VB.Net中,这就像
Dim oAttach as outlook.Attachment = myItems.Attachments(0);希望它能帮上忙
发布于 2011-03-16 08:21:39
在您正在查看的代码项目示例代码中,附件位应该在循环中,因此:
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
Nexthttps://stackoverflow.com/questions/5322389
复制相似问题