Microsoft 365 – PowerShell – Options to send mail – part 2 – exploring Send-PnPMail

fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET
fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET

Hi All,

Greetings for the day!!! Today new learning 🙂

We are discussing how to send email through PowerShell in Microsoft 365.

In last article we discussed – how to send email using Send-MailMessage PowerShell CMDLET – Microsoft 365 – PowerShell – Options to send mail – part1 – exploring Send-MailMessage PowerShell CMDLET

Send-MailMessage CMDLET is deprecated. In this article we will discuss alternative approach using PnP CMDLET – Send-PnPMail

Details

Syntax:

Send-PnPMail -To <String[]> -Subject <String> -Body <String> [-Cc <String[]>] [-Bcc <String[]>] [-Connection <PnPConnection>] [-Verbose]

  • This PowerShell CMDLET sends the email using current site context
  • Example

Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com

Send-PnPMail -To "prasham1@knowledgejunction1.onmicrosoft.com" -Subject "Today is FUNDAY :) LIFE IS BEAUTIFUL" -Body "Today is FUNDAY :) LIFE IS BEAUTIFUL :)"

fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET
fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET
  • In above example, mail is sent using site context – https://knowledgejunction1.sharepoint.com
  • Mail is sent to user – prasham1@knowledgejunction1.onmicrosoft.com (Prasham1 Sabadra)
  • Following is the inbox of user – prasham1@knowledgejunction1.onmicrosoft.com (Prasham1 Sabadra)

fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET – Inbox of user – prasham1@knowledgejunction1.onmicrosoft.com (Prasham1 Sabadra) – mail received successfully
fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET – Inbox of user – prasham1@knowledgejunction1.onmicrosoft.com (Prasham1 Sabadra) – mail received successfully

fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET – Inbox of user – prasham1@knowledgejunction1.onmicrosoft.com (Prasham1 Sabadra) – mail received successfully - check the from address - Site Title of the site to which we connected
fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET – Inbox of user – prasham1@knowledgejunction1.onmicrosoft.com (Prasham1 Sabadra) – mail received successfully – check the from address – Site Title of the site to which we connected along with the email address – no-reply@sharepointonline.com
  • Here please note the from address of mail – title of the site of which we are using context to send an email and from email address is – no-reply@sharepointonline.com as in below fig

fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET - notice the site title through which context we are sending mail
fig : Microsoft 365 – PowerShell – exploring Send-PnPMail PowerShell CMDLET – notice the site title through which context we are sending mail

We have some very good articles related to Mail and Microsoft 365

REFERENCES

Thanks for reading !!! HAVE a FANTASTIC LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.