question

HAQINZMAMUL-8293 avatar image
0 Votes"
HAQINZMAMUL-8293 asked VikiJi-MSFT commented

how to send and receive email using Microsoft exchange in PowerShell

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.

windows-server-powershelloffice-exchange-server-dev
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi HAQINZMAMUL-8293,
Welcome to Q&A forum!
I have removed the tag office-online-server-exchange that focuses on general issues about integrating Office Online Server with Exchange Server.
Thanks for your understanding.

0 Votes 0 ·

Any guidance as to what tag should be used when asking for help with Exchange Web Services? Is that even covered in the Q&A forum? If it's not, where should someone be looking for help? Stack Overflow?

0 Votes 0 ·

Hi @HAQINZMAMUL-8293,
I have added a relevant tag for you. Thanks.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HAQINZMAMUL-8293 avatar image
0 Votes"
HAQINZMAMUL-8293 answered

@RichMatheisen-8856 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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.