Attachment von eingehenden Emails automatisch speichern (Exchange Server)

Durch den Einsatz des nachfolgenden Skripts im Agent des Exchange Server kann man die Attachment’s einer Email automatisch in einem lokalen Verzeichnis speichern.

Um ein überschreiben der Dateien zu vermeiden wird ein temporärer Dateiname gebildet.

Um das Skript ausführen zu können muss in jedem Fall ein Exchange Server betrieben werden.

Hier nun das Skript:

<SCRIPT language=VBScript RunAt="Server">

'------------------------------------------------------------------------------
'FILE DESCRIPTION: Exchange Server Event Script
'------------------------------------------------------------------------------

OptionExplicit

'------------------------------------------------------------------------------
' Global Variables
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' Event Handlers
'------------------------------------------------------------------------------

' DESCRIPTION: This event is fired when a new message is added to the folder
PublicSub Folder_OnMessageCreated
Dim objSession
Dim objItem
Dim objAttachment
dim i
dim atName

Set objSession = EventDetails.Session

Set objItem = objSession.GetMessage(EventDetails.MessageID, Null)

If objItem.Type ="IPM.Note"or objItem.Type ="IPM.Post"Then
If objItem.Attachments.Count > 0 then
for i = 1 to objItem.Attachments.Count
Set objAttachment = objItem.Attachments.Item(i)
atName ="C:\Attachment\Inbox\" & GetTempName("C:\Attachment\Inbox\")
ifNot FileExist(atName) then
objAttachment.WriteToFile(atName)
else
objAttachment.WriteToFile(atName & "neu")
EndIf
next
endif
EndIf

Set objAttachment =nothing
Set objSession =Nothing
Set objItem =Nothing

EndSub

--------------------------------------------------------------------------------

' DESCRIPTION: This event is fired when a message in the folder is changed
PublicSub Message_OnChange
EndSub

--------------------------------------------------------------------------------

' DESCRIPTION: This event is fired when a message is deleted from the folder
PublicSub Folder_OnMessageDeleted
EndSub

--------------------------------------------------------------------------------

' DESCRIPTION: This event is fired when the timer on the folder expires
PublicSub Folder_OnTimer
EndSub

--------------------------------------------------------------------------------

Function FileExist(filespec)
Dim fso, msg
Dim bRet
Set fso =CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
bRet =true
Else
bRet =false
EndIf
FileExist = bRet
EndFunction

--------------------------------------------------------------------------------

Function GetTempName(path)
Dim fso, fsp
Dim bRet
Set fso =CreateObject("Scripting.FileSystemObject")
fsp = fso.GetTempName
GetTempName = fsp
EndFunction

</SCRIPT>