

The code to connect to the Graph is straightforward: You can embellish it by adding an attachment (perhaps a new employee guide) or changing the set of recipients. The script is basic (you can download it from GitHub) but does enough to prove the principal.

The script runs interactively, so we need to be aware of permission creep on the service principal used to connect to the Graph. In this instance, we need the Mail.Send and Mail.ReadWrite permissions. Like all connections to the Graph, you need permissions to access data. Connects to the Microsoft Graph to create and send the email.Connects to Exchange Online to find the mailboxes for employees added in the last 7 days.To automate the process, the script does the following:

#Online email sender how to
The email usually contains helpful tips about working in the organization and things which new employees need to know, like how to find the cafeteria. Organizations commonly send welcome email to new employees as part of their onboarding process. In this article, I explain a second alternative to the Send-MailMessage cmdlet by using the New-MgUserMessage and Send-MgUserMessage cmdlets from the SDK to create and send a welcome message to new employees. I used the Microsoft Graph SDK for PowerShell to solve the first problem and native Graph API calls for the second. Although Microsoft has exempted the SMTP AUTH protocol for now, it’s wise to prepare to consider alternatives to PowerShell’s Send-Message cmdlet like the Graph SendMail API. The well-founded campaign to remove support for basic authentication from Exchange Online connectivity protocols by October 2022.Microsoft’s decision to move to a new licensing platform in 2022, which means that some Azure AD cmdlets won’t work after June 30, 2022.Among the recent factors causing me to consider using Graph APIs with PowerShell are: Recently, I’ve been exploring how to use the Microsoft Graph with PowerShell to automate some common Microsoft 365 administrative tasks like how to send Exchange Online mail to report the outcome of scripts.
