Introduction
There are many situations where a developer or automation engineer wants to read the mailbox in order to process and facilitate the automation process.
Unlike Sending an email using Send-Mail
cmdlet, PowerShell does not natively support fetching mails from a mailbox.
However, there are few modules that we could use to achieve the same. In this post, we are going to look how to do exactly the same using a third party PowerShell module named Mailozaurr
About mailoazurr module
Mailoazurr is a cross-platform PowerShell module written by Jeffery Steadfast that provides easy way to interact emails using SMTP, POP3, IMAP etc.
Procedure
Install the required module
Before we get started, we need to install the required module using following command.
Provide mailbox authentication details
For sake of simplicity and to focus on the core functionality of fetching POP3 mailbox we are going to use simple authentication. However, note that the module mailoazurr
does provide OAuth support for some of the mail providers such as Google and Microsoft Identity
Connect to the POP3 Server
Fetch Messages
The mailoazurrmodule provide a convenient way fetch mail. Lets first look at the cmdlet to fetch the email message and then understand it better
In above example $connectionDetails
is the connection we created in previous step to the POP3 server.
The Get-POP3Message
cmdlet provides an easy way to fetch a portion of messages using -Index and -Count parameters
The -Index parameters tells from which index the messages should start fetching. All messages previous to index are skipped.
The -Count parameter tells how many messages should be fetched.
In above example we are fetching 10 mails starting from 5 th mail.
Disconnect server
The last step is to disconnect connection to the server once we are done
Conclusion
In this post we looked a way to retrieve POP3 messages from the mailbox.