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 CMDLETSend-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 Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

    You may also like...

    Leave a Reply

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

    %d bloggers like this: