how to send and receive email using Microsoft exchange in PowerShell

HAQ, INZMAM UL 21 Reputation points
2021-11-05T15:12:47.263+00:00

Hi Team,

I want to send email from O365 Microsoft Exchange using PowerShell script. I have tried to look for some solution online but did not get any. I am trying to create a PowerShell script which can help me to send email from O365 exchange and also read emails from the Mailbox folder.

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
505 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,354 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 44,621 Reputation points
    2021-11-05T19:28:48.403+00:00

    You can use Send-MailMessage to send SMTP messages, but use it with caution: DE0005.md

    Receiving mail is another thing entirely. PowerShell has no built-in way to do that. You can use the Outlook COM application, but it's not that easy to deal with. You can use a POP3 client, but if you want to do it in PowerShell you'd have to be able to deal with MIME, and that's another problem. You can also use EWS (Exchange Web Services), but that has its own learning curve (although it's not as steep as Outlook's COM model).

    Have a look at MailKit and MIMEKit instead.

    0 comments No comments

  2. HAQ, INZMAM UL 21 Reputation points
    2021-11-06T15:18:45.447+00:00

    @Rich Matheisen thanks for your response!

    I can not use Outlook COM because i can not install outlook application there and would not like to use POP3 either. I want to know how can i use EWS in PowerShell to send and receive email.

    0 comments No comments

  3. Rich Matheisen 44,621 Reputation points
    2021-11-06T17:44:19.157+00:00

    Have a look here: start-using-web-services-in-exchange
    If you prefer the PDF version: a483b55d6f0a4224c75f9a2d64de7783

    A while back (when EWS was introduced) Glen Scales did a lot of work and development with EWS. It looks like he's still doing it.

    gscales
    gsexdev.blogspot.com

    You'll find plenty of examples if you search for them.

    0 comments No comments