我试图找到一种方式来获得邮件附件(programaticaly),然后打开它......有人可以告诉我如何做到这一点或点我到正确的方向?获得的前景/打开邮件附件
0
A
回答
1
这是一个VBA脚本(在Outlook中的宏用),这将循环遍历当前文件夹中的所有选择项的所有附件,并将它们保存到磁盘。
它应该让你开始,我不认为这会花费太多添加某种进程启动,而不是保存逻辑吧。
Public Sub SaveAttachments()
'Note, this assumes you are in the a folder with e-mail messages when you run it.
'It does not have to be the inbox, simply any folder with e-mail messages
Dim Exp As Outlook.Explorer
Dim Sel As Outlook.Selection
Dim AttachmentCnt As Integer
Dim AttTotal As Integer
Dim MsgTotal As Integer
Dim outputDir As String
Dim outputFile As String
Dim fileExists As Boolean
Dim cnt As Integer
'Requires reference to Microsoft Scripting Runtime (SCRRUN.DLL)
Dim fso As FileSystemObject
Set Exp = Application.ActiveExplorer
Set Sel = Exp.Selection
Set fso = New FileSystemObject
outputDir = "C:\Path"
If outputDir = "" Then
MsgBox "You must pick an directory to save your files to. Exiting SaveAttachments.", vbCritical, "SaveAttachments"
Exit Sub
End If
Dim att As Attachment
'Loop thru each selected item in the inbox
For cnt = 1 To Sel.Count
'If the e-mail has attachments...
If Sel.Item(cnt).Attachments.Count > 0 Then
MsgTotal = MsgTotal + 1
'For each attachment on the message...
For AttachmentCnt = 1 To Sel.Item(cnt).Attachments.Count
'Get the attachment
Set att = Sel.Item(cnt).Attachments.Item(AttachmentCnt)
outputFile = att.FileName
outputFile = Format(Sel.Item(cnt).ReceivedTime, "yyyy-mm-dd_hhmmss - ") + outputFile
fileExists = fso.fileExists(outputDir + outputFile)
'Save it to disk if the file does not exist
If fileExists = False Then
att.SaveAsFile (outputDir + outputFile)
AttTotal = AttTotal + 1
End If
Set att = Nothing
Sel.Item(cnt).Close (Outlook.OlInspectorClose.olDiscard)
Next
End If
Next
'Clean up
Set Sel = Nothing
Set Exp = Nothing
Set fso = Nothing
'Let user know we are done
Dim doneMsg As String
doneMsg = "Completed saving " + Format$(AttTotal, "#,0") + " attachments in " + Format$(MsgTotal, "#,0") + " Messages."
MsgBox doneMsg, vbOKOnly, "Save Attachments"
Exit Sub
ErrorHandler:
Dim errMsg As String
errMsg = "An error has occurred. Error " + Err.Number + " " + Err.Description
Dim errResult As VbMsgBoxResult
errResult = MsgBox(errMsg, vbAbortRetryIgnore, "Error in Save Attachments")
Select Case errResult
Case vbAbort
Exit Sub
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
End Sub
1
Look for the COM-reference of Outlook. 您还可以使用VBA编写的宏来做到这一点。
+0
另请看这个:http://www.fontstuff.com/outlook/oltut01.htm – 2011-04-19 08:21:36
相关问题
- 1. PHP - 邮件附件无法打开
- 2. 未在Mac邮件中打开的PHP邮件()附件
- 3. Windows phone 7开发打开邮件附件的应用程序
- 4. 直接打开.ics文件事件没有邮件附件
- 5. 当前打开电子邮件
- 6. Applescript - 拖放文件附件以打开新电子邮件
- 7. 从iOS的邮件附件中打开flex应用程序
- 8. 如何打开默认的电子邮件客户端附件
- 9. 通过VB.Net将文件附加到已打开的邮件
- 10. 打开带附件的电子邮件客户端
- 11. 带附件的公开电子邮件
- 12. 打开邮件箱
- 13. CasperJS获得前5名雅虎邮件
- 14. 获得一个打开的文件的
- 15. 从邮件打开文件
- 16. 如何获得具有.eml附件的邮件正文?
- 17. Android - 用附件提示打开电子邮件意向
- 18. Python:打开雷鸟用附加文件写新邮件
- 19. 文件附加到电子邮件 - 我试图打开MYAPP
- 20. 在iOS4应用程序中打开邮件附件
- 21. 在Android中打开电子邮件附件
- 22. 电子邮件附件在应用程序中打开?
- 23. intent过滤器打开.shtml附件从电子邮件...
- 24. Javascript:打开Outlook并将附件添加到新电子邮件
- 25. 打开电子邮件活动并获得结果?
- 26. Android:获取并打开电子邮件
- 27. 获取当前活动(或打开)的邮箱名称电子邮件
- 28. 如何打开PDF附件
- 29. 邮件附件
- 30. 打印前文件打开?
你将不得不与.NET中的前景COM /互操作的图书馆合作,你会看到它添加在COM引用,并有大量的资源在网络上 – 2011-04-19 08:20:45
我使用Microsoft.Office。 Interop.Outlook(用C#),但我不能让mail.Attachments.Item ......唯一的选择就是加... – Wolfy 2011-04-19 11:01:08
OK,我的错误:),现在它的伟大工程... TNX所有 – Wolfy 2011-04-21 17:49:46