我試圖找到一種方式來獲得郵件附件(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