如何使用 VB.Net 通过 Outlook 仅检索特定人员的邮件?
我从 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
部分:未找到类型“对象”上的公共成员“附件”。我需要此函数来检索附件。我尝试过不同的方法,但没有任何效果。你能帮我吗?
I got the following code from 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
Now, I got as far as making the default folder the Inbox. What I would like to do is to extend the functionality by retrieving only a specific person's emails and extracting and saving whatever attachments he/she sends. Also, I get the following error when the code reaches theDim Atmt as Outlook.Attachment
part: Public member 'Attachment' on type 'Object' not found. I need this function to retrieve the attachments. I've tried different things, but nothing's worked. Can you please help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新 2 个
暗淡项目作为新字典(字符串、字符串)
对于 x = 1 到 myItems.Count
'来自特定人的邮件
如果 myItems.Item(x).SenderEmailAddress = "[电子邮件受保护]"然后
对于每个 Atmt 作为 Outlook.Attachment 在 myItems(x).Attachment
尝试此代码
在 VB.Net 中它会像
希望它有帮助
Update 2
Dim items As New Dictionary(Of String, String)
For x = 1 To myItems.Count
'Mail from a specific person
If myItems.Item(x).SenderEmailAddress = "[email protected]" Then
For Each Atmt As Outlook.Attachment In myItems(x).Attachment
Try this code
In VB.Net it will be like
Hope it helps
在您正在查看的 codeproject 示例代码中,附件位应该位于循环内部,因此:
In the codeproject sample code you're looking at, the attachment bit is supposed to be inside the loop, so: