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

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 :)"
- 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)


- 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

We have some very good articles related to Mail and Microsoft 365
- Microsoft 365 : Exchange Online / PowerShell – PowerShell – Resolving error – Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail – https://knowledge-junction.in/2023/02/07/microsoft-365-exchange-online-powershell-resolving-error-send-mailmessage-the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated-the-server-response-was-5-7-57-c/
- M365: Microsoft Graph – Part 10 – Send Email using Graph API from Console Application (Background Job) – https://knowledge-junction.in/2020/03/15/m365-microsoft-graph-part-10-send-email-using-graph-api-from-console-application-background-job/
- Share Multiple Attachments of SharePoint List via Email using Power Automate – https://knowledge-junction.in/2021/02/13/share-multiple-attachments-of-sharepoint-list-via-email-using-power-automate/
- Power Platform : Power Automate – sending email to SharePoint group (all users / members of the SharePoint group) – https://knowledge-junction.in/2022/07/13/power-platform-power-automate-sending-email-to-sharepoint-group-all-users-members-of-the-sharepoint-group/
REFERENCES
Thanks for reading !!! HAVE a FANTASTIC LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂
You must be logged in to post a comment.