I need a powershell script that will download mail sent to a mailbox from a specific email address to a folder path such as \\server01\temp

Thor2923
Thor2923 used Ask the Experts™
on
I need a power shell script to checks a specific email address or mailbox on our Exchange server, lets say xyz@domain.com and every time I receives and email from another specific address, lets say abc@comp;any.com it downloads the email and attachment to a folder such as \\server01\temp......Is there a quick way to write a powershell script for this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sebastian StrittmatterSoftware Development

Commented:
What access methods do you have to access your mailbox?
 
 * IMAP
 * Outlook
 * something else.

Author

Commented:
we are using exchange 2013 i know we use IMAP and OUTLOOK....I maybe I should have made this more of an exchange question than PowerShell
Michael B. SmithManaging Consultant

Commented:
Why not simply use Search-Mailbox?
Software Development
Commented:
I wrote a little script for this.
For this script you need outlook with the specfic mail account. You can run this script as task in a time period.

The script marks the worked messages as read.

I hope this helps.

param(
    [string]$nameOfOutlookAccount, # Name of outlook-Accoun have to be visible in outlook
    [string]$nameOfInboxFolder,    # name of the inbox folder visible in outlook
    [string]$emailOfSender,        # name of the sender mail
    [string]$attachTargetPath      # path for the attachments
)

$out = New-Object -ComObject Outlook.Application

$mapi = $out.GetNamespace("MAPI")


$account = $mapi.Folders.Item($nameOfOutlookAccount);

$inbox = $account.Folders.Item($nameOfInboxFolder);

# Loop through inbox
$inbox.Items | % {
    if($_.UnRead -eq $true -and $_.SenderEmailAddress -eq $emailOfSender) {
        # Save the attachment to directory an mark message as read
        $_.Attachments | % {
            $p = $(Resolve-Path "$attachTargetPath\").Path
            $_.SaveAsFile("$($p)$($_.FileName)")
            Write-Host "Saved Attachment $($p)$($_.FileName)"
        }

        $_.UnRead = $false
        Write-Host "Marked message as read" -ForegroundColor Green
    }
}

# Close Outlook     
$out.Quit();

Open in new window

Author

Commented:
this was fantastic thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial