I'm trying to figure out a way to copy an attachment from a specific Mailbox to a folder on our exchange server so it can then be pushed to splunk.
The attachment in question is a log file generated by a cloud based application - our auditors gave us the surprise requirement that this log file now needs to be automatically uploaded into splunk (previously automated email reports were adequate).
The Exchange server is a on-prem 2013, the Splunk is on prem also. I've dabeled in VBA for an outlook script, but I dont want to corner myself into making sure I have a dedicated outlook install for it - I would like it to just be an automated task or scheduled script that runs on the exchange server.
I'm currently playing with the search-mailbox feature in exchange shell - but haven't found any functionality that looks like it can help me.
I already have the local hot-folder for splunk configured, that was the easy part.
Thanks!
You may consider using EWS, see Explore the EWS Managed API, EWS, and web services in Exchange for more information.
The following code example shows how to get an
EmailMessage
object by using theBind
method, then iterate through the attachment collection and call theFileAttachment.Load
orItemAttachment.Load
method on each attachment as appropriate. Each file attachment is saved to theC:\temp\
folder, and each item attachment is loaded into memory. For information about how to save an item attachment, see Save an attached email by using the EWS Managed API.As for PowerShell, you may find the Exchange Server PowerShell (Exchange Management Shell) section in MSDN helpful.