# Script for reading mail

**URL:** <https://forums.powershell.org/t/script-for-reading-mail/19258>\
**Category:** PowerShell Help\
**Created:** [May 6, 2022, 5:11pm UTC](https://forums.powershell.org/t/script-for-reading-mail/19258 "2022-05-06T17:11:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvleer](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@bvleer](https://forums.powershell.org/u/bvleer)\
**Post date:** [May 6, 2022, 5:11pm UTC](https://forums.powershell.org/t/script-for-reading-mail/19258/1 "2022-05-06T17:11:19Z")

</div>

Hi, I want to develop a script that reads the mapi mailbox of a certain user, saves all attachments of the mails from which the subject contains a certain string. Save folder should be dependent on certain information in the body of the mail. Any suggestions to get me started are welcome.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [May 6, 2022, 5:25pm UTC](https://forums.powershell.org/t/script-for-reading-mail/19258/2 "2022-05-06T17:25:48Z")

</div>

I googled it for you and found some sites you may find helpful as a starting point 😉

> **[Saving Outlook attachments with PowerShell](https://bronowski.it/blog/2020/09/saving-outlook-attachments-with-powershell/)**
>
> Save attachments from hundreds of emails received via Microsoft Outlook using PowerShell.

> <https://stackoverflow.com/questions/54365547/using-powershell-to-save-outlook-attachments>

[https://social.technet.microsoft.com/Forums/windowsserver/en-US/11218cf2-eb24-4110-967f-b29234064501/how-do-i-save-outlook-attachments-using-powershell?forum=winserverpowershell](https://social.technet.microsoft.com/Forums/windowsserver/en-US/11218cf2-eb24-4110-967f-b29234064501/how-do-i-save-outlook-attachments-using-powershell?forum=winserverpowershell)

[https://www.example-code.com/powershell/imap\_downloadAttachment.asp](https://www.example-code.com/powershell/imap_downloadAttachment.asp)

> **[powershell to download attachment](https://community.spiceworks.com/topic/2050871-powershell-to-download-attachment)**
>
> I want to download some attachment from outlook 2016 either download directly to a folder or  rename the attachment and copy over to a network folder...It didn't work when using...

---

<div class="post-metadata">

**Author:** ![bvleer](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@bvleer](https://forums.powershell.org/u/bvleer)\
**Post date:** [May 6, 2022, 5:31pm UTC](https://forums.powershell.org/t/script-for-reading-mail/19258/3 "2022-05-06T17:31:26Z")

</div>

Thnx but my main challenge is to be able to specify the username and password somewhere. The examples you provided seem to use my own mailbox, that is not wanted.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [May 6, 2022, 5:45pm UTC](https://forums.powershell.org/t/script-for-reading-mail/19258/4 "2022-05-06T17:45:37Z")

</div>

The StackOverflow thread has a link explaining how to use EWS to accomplish this task.

Another idea would be to run the PowerShell session _as the desired user_ or to use the task scheduler to impersonate the desired user and run the script in its context.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/script-for-reading-mail/19258/5 "2024-05-16T20:18:00Z")

</div>


