{"id":57352,"date":"2022-11-01T06:00:00","date_gmt":"2022-11-01T10:00:00","guid":{"rendered":"https:\/\/practical365.com\/?p=57352"},"modified":"2025-01-07T06:26:38","modified_gmt":"2025-01-07T11:26:38","slug":"send-email-powershell-graph","status":"publish","type":"post","link":"https:\/\/practical365.com\/send-email-powershell-graph\/","title":{"rendered":"Practical Graph: Ways to Send Email via the Microsoft Graph"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/#Microsoft_Offers_Raw_APIs_and_Two_SDK_Methods\" >Microsoft Offers Raw APIs and Two SDK Methods<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/#The_Independent_Send-EmailMessage_cmdlet\" >The Independent Send-EmailMessage cmdlet<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/#Deciding_Between_the_Two_SDK_Cmdlets\" >Deciding Between the Two SDK Cmdlets<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/#Testing_Send-MgUserMail\" >Testing Send-MgUserMail<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/#Dealing_with_Permissions\" >Dealing with Permissions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/#Decision_Time\" >Decision Time<\/a><\/li><\/ul><\/nav><\/div>\n<div id=\"bsf_rt_marker\"><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-microsoft-offers-raw-apis-and-two-sdk-methods\"><span class=\"ez-toc-section\" id=\"Microsoft_Offers_Raw_APIs_and_Two_SDK_Methods\"><\/span>Microsoft Offers Raw APIs and Two SDK Methods<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>SMTP AUTH remains an Exchange Online connection protocol that supports basic authentication. Microsoft was forced to exclude it from the set of protocols it is in the final stages of retiring. Too many organizations have too many devices and apps that send email via Exchange Online for Microsoft to pull the plug on SMTP AUTH. However, there\u2019s no doubt that this will happen. The only question is when.<\/p>\n\n\n\n<p>The replacement is to use the Microsoft Graph APIs to create and send email. Over the last year or so, I\u2019ve been investigating the available methods. Microsoft offers the following Graph-based options:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <a href=\"https:\/\/practical365.com\/upgrade-powershell-scripts-sendmailmessage\/\" target=\"_blank\" rel=\"noreferrer noopener\">Graph sendMail API<\/a>.<\/li>\n\n\n\n<li>The <a href=\"https:\/\/practical365.com\/send-mail-exchange-online-graph-powershell\/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Send-MgUserMessage<\/em> cmdlet in the Microsoft Graph PowerShell SDK<\/a>.<\/li>\n\n\n\n<li>The <em>Send-MgUserMail<\/em> cmdlet in the Microsoft Graph PowerShell SDK.<\/li>\n<\/ul>\n\n\n\n<p>Why does the Microsoft Graph PowerShell SDK include two methods to do the same job? One answer lies in the way that Microsoft generates SDK cmdlets automatically using the AutoRest process. If an API exists, the SDK gets a cmdlet. And because the Graph includes the <em><a href=\"https:\/\/learn.microsoft.com\/en-us\/graph\/api\/message-send?WT.mc_id=M365-MVP-9501\" target=\"_blank\" rel=\"noreferrer noopener\">message: send API<\/a><\/em> and the <a href=\"https:\/\/learn.microsoft.com\/en-us\/graph\/api\/user-sendmail?WT.mc_id=M365-MVP-9501\" target=\"_blank\" rel=\"noreferrer noopener\"><em>user: sendMail<\/em> API<\/a>, the SDK glories in two cmdlets that both send email via Exchange Online. But more importantly, each cmdlet serves a different purpose. We\u2019ll get to that soon.<\/p>\n\n\n\n<div class=\"q-blockads-inside-content q-blockads-entity-placement\" id=\"q-blockads-3053127561\"><div id=\"q-blockads-801372707\"><p><a href=\"https:\/\/www.quest.com\/P365_On_Demand_Migration\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-62892\" src=\"https:\/\/practical365.com\/wp-content\/uploads\/2024\/09\/1901-10-20-2025-Redone-300x31.jpg\" alt=\"\" width=\"861\" height=\"89\" srcset=\"https:\/\/practical365.com\/wp-content\/uploads\/2024\/09\/1901-10-20-2025-Redone-300x31.jpg 300w, https:\/\/practical365.com\/wp-content\/uploads\/2024\/09\/1901-10-20-2025-Redone-768x80.jpg 768w, https:\/\/practical365.com\/wp-content\/uploads\/2024\/09\/1901-10-20-2025-Redone.jpg 860w\" sizes=\"auto, (max-width: 861px) 100vw, 861px\" \/><\/a><\/p>\n<\/div><\/div><h2 class=\"wp-block-heading\" id=\"h-the-independent-send-emailmessage-cmdlet\"><span class=\"ez-toc-section\" id=\"The_Independent_Send-EmailMessage_cmdlet\"><\/span>The Independent Send-EmailMessage cmdlet<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you don\u2019t fancy Microsoft\u2019s cmdlets, Przemyslaw Klys, the developer of the well-respected <a href=\"https:\/\/github.com\/EvotecIT\/PSWriteHTML\">PSWriteHTML<\/a> PowerShell module, <a href=\"https:\/\/evotec.xyz\/easy-way-to-send-emails-using-microsoft-graph-api-office-365-with-powershell\/\" target=\"_blank\" rel=\"noreferrer noopener\">offers his own take on the topic in the Send-EmailMessage cmdlet.<\/a> This cmdlet is in the <a href=\"https:\/\/github.com\/EvotecIT\/Mailozaurr\" target=\"_blank\" rel=\"noreferrer noopener\">splendidly-named Mailozaurr module<\/a>.<\/p>\n\n\n\n<p>Unlike the Microsoft Graph PowerShell SDK cmdlets, Przemyslaw\u2019s work exhibits the hallmarks of some thoughtful programming to make it as easy as possible to create and send messages. For instance, Microsoft\u2019s cmdlets require special processing for large attachments (anything over 3 MB), which can be a real hindrance (see this <a href=\"https:\/\/gsexdev.blogspot.com\/2021\/09\/sending-message-with-large-attachment.html\" target=\"_blank\" rel=\"noreferrer noopener\">article by MVP Glen Scales<\/a>). The <em>Send-EmailMessage<\/em> cmdlet handles large attachments automatically, which is exactly the way Microsoft\u2019s cmdlets should do.<\/p>\n\n\n\n<p>The reason why people use Microsoft\u2019s APIs is because they are Microsoft\u2019s APIs. Although a better independent alternative might exist, organizations might be loath to write code based on a module that isn\u2019t formally supported. Of course, in-house developers could do exactly what Przemyslaw did and build a better wrapper around the Graph APIs, but I can\u2019t see many rushing to do that. In any case, take a look at the Mailozaurr module and make your own mind up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-deciding-between-the-two-sdk-cmdlets\"><span class=\"ez-toc-section\" id=\"Deciding_Between_the_Two_SDK_Cmdlets\"><\/span>Deciding Between the Two SDK Cmdlets<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Given the choice between the two SDK cmdlets, which one should you use? Previously, I covered <a href=\"https:\/\/practical365.com\/send-mail-exchange-online-graph-powershell\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to send emails using the <em>Send-MgUserMessage<\/em> cmdlet<\/a>. The <em>Send-MgUserMail<\/em> cmdlet is easier to use because you can create and send a message with a single command instead of creating a draft message first (with <em>New-MgUserMessage<\/em>) and then sending it.<\/p>\n\n\n\n<p>By itself, creating and sending in one motion probably makes <em>Send-MgUserMail<\/em> a good choice for most scenarios when apps need to send email. Typically, these messages are something like a notification to let someone know about some information, like a job finishing or something to check (like <a href=\"https:\/\/practical365.com\/azure-ad-apps-review-permissions\/\" target=\"_blank\" rel=\"noreferrer noopener\">highly-permissioned Azure AD apps<\/a>).<\/p>\n\n\n\n<p><em>Send-MgUserMessage<\/em> does have some tricks up its sleeve. Because it sends an already-created message, it can handle scenarios like replies and message forwards. However, I think relatively few apps need to process draft messages or respond to inbound mail, this capability might not be as useful as it seems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-testing-send-mgusermail\"><span class=\"ez-toc-section\" id=\"Testing_Send-MgUserMail\"><\/span>Testing Send-MgUserMail<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To test how easy it is to use the <em>Send-MgUserMail<\/em> cmdlet, I converted the sample script I used with <em>Send-MgUserMessage<\/em>. This script sends a welcome message to new employees. It uses the <em>Get-ExoMailbox<\/em> cmdlet to find mailboxes created within the last week. This is logical because if we\u2019re going to send a welcome message, it needs to go to a mailbox. If you didn\u2019t want to load the Exchange Online management module, something similar could be done with:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$CheckDate = (Get-Date).AddDays(-7)\n[array]$Users = Get-MgUser -All -Filter \"userType eq 'Member'\"\n$Users = $Users | Where-Object {$_.CreatedDateTime -gt $CheckDate}\n<\/pre>\n\n\n\n<p>This command works perfectly well, but its performance is not going to be sparkling in larger tenants. The <em>Get-MgUser<\/em> cmdlet doesn\u2019t support filtering against an account\u2019s creation date, so to find the set of recently created accounts, we must fetch all accounts and then apply a&nbsp;client-side filter. By comparison, the <em>Get-ExoMailbox<\/em> cmdlet can happily use a server-side filter, meaning that Exchange Online only returns the set of target mailboxes.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[array]$Users = (Get-ExoMailbox -Filter \"WhenMailboxCreated -gt '$CheckDate'\" -RecipientTypeDetails UserMailbox -ResultSize Unlimited -Properties WhenMailboxCreated | Select WhenMailboxCreated, DisplayName, UserPrincipalName, PrimarySmtpAddress)<\/pre>\n\n\n\n<p>When I wrote about <em>Send-MgUserMessage<\/em>, I noted that the cmdlet uses arrays to pass recipients for the message and said that the SDK developers could do us all a favor by making this part of building out message properties easier. A PowerShell function does the trick and can handle To, Cc, and Bcc recipients.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Function Populate-MessageRecipient { # Build a list of recipients for a message\n    [cmdletbinding()]\n    Param(\n        [array]$ListOfAddresses )\n    ForEach ($SMTPAddress in $ListOfAddresses) {\n        @{\n            emailAddress = @{address = $SMTPAddress}\n        }    \n    }    \n}\n<\/pre>\n\n\n\n<p>To add recipients, we create an array holding the SMTP address for each recipient and put it through the function to create the array to add to the message properties. For example, this code adds two recipients (a distribution group and a mailbox) as Cc recipients.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$CcRecipientList = @( \n        'Tenant.Admins@office365itpros.com'\n        'Kim.Akers@Office365itpros.com' )\n[array]$MsgCcRecipients = Populate-MessageRecipient -ListOfAddresses $CcRecipientList\n<\/pre>\n\n\n\n<p>The remainder of the script:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prepares an attachment encoded in Base64.<\/li>\n\n\n\n<li>Customizes the message content for the recipient and builds an HTML message body.<\/li>\n\n\n\n<li>Populates the set of message properties (subject, To recipients, Cc recipients, attachment, and the message body).<\/li>\n\n\n\n<li>Populates two message parameters (save the message to sent items and ask for a delivery receipt).<\/li>\n\n\n\n<li>Sends the message with <em>Send-MgUserMail<\/em>.<\/li>\n<\/ul>\n\n\n\n<p>Here\u2019s the code (the full script is <a href=\"https:\/\/github.com\/12Knocksinna\/Office365itpros\/blob\/master\/SendWelcomeMessage-UserMail.PS1\" target=\"_blank\" rel=\"noreferrer noopener\">available from GitHub<\/a>):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$MsgAttachment = @(\n\t@{\n\t\"@odata.type\" = \"#microsoft.graph.fileAttachment\"\n\tName = ($AttachmentFile -split '\\\\')[-1]\n\tContentType = \"text\/plain\"\n\tContentBytes = $EncodedAttachmentFile\n\t} \n)\n\nForEach ($User in $Users) {\n  $ToRecipientList   = @( $User.PrimarySmtpAddress )\n  [array]$MsgToRecipients = Populate-MessageRecipient -ListOfAddresses $ToRecipientList\n  Write-Host \"Sending welcome email to\" $User.DisplayName\n  # Customize the message \n  $htmlHeaderUser = \"&lt;h2>New User \" + $User.DisplayName + \"&lt;\/h2>\"    \n  $HtmlMsg = \"&lt;\/body>&lt;\/html>\" + $HtmlHead + $htmlheaderuser + $htmlbody + \"&lt;p>\"\n  # Construct the message body\n  $MsgBody = @{\n     Content = \"$($HtmlMsg)\"\n     ContentType = 'html'   }\n\n  $Message =  @{subject           = $MsgSubject}\n  $Message += @{toRecipients      = $MsgToRecipients}  \n  $Message += @{ccRecipients      = $MsgCcRecipients}  \n  $Message += @{attachments       = $MsgAttachment}\n  $Message += @{body              = $MsgBody}\n  $Params   = @{'message'         = $Message}\n  $Params  += @{'saveToSentItems' = $True}\n  $Params  += @{'isDeliveryReceiptRequested' = $True}\n\n  Send-MgUserMail -UserId $MsgFrom -BodyParameter $Params\n}\nWrite-Host \"All done. Messages sent!\"\n<\/pre>\n\n\n\n<p>Everything works and our new employees receive a nice welcome message (Figure 1).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"670\" src=\"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/Welcome-Message-1-1024x670.jpg\" alt=\"The welcome message generated by Send-MgUserMail\" class=\"wp-image-57354\" srcset=\"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/Welcome-Message-1-1024x670.jpg 1024w, https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/Welcome-Message-1-300x196.jpg 300w, https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/Welcome-Message-1-768x502.jpg 768w, https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/Welcome-Message-1-1536x1005.jpg 1536w, https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/Welcome-Message-1.jpg 1553w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 1: The welcome message generated by Send-MgUserMail<\/figcaption><\/figure>\n<\/div>\n\n\n<div class=\"q-blockads-content q-blockads-entity-placement\" id=\"q-blockads-1406578852\"><div id=\"q-blockads-4028073546\"><p><a href=\"https:\/\/www.quest.com\/Security_Guardian_P365\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-62893\" src=\"https:\/\/practical365.com\/wp-content\/uploads\/2024\/04\/1902-10-20-2025-Redone-300x31.jpg\" alt=\"\" width=\"861\" height=\"89\" srcset=\"https:\/\/practical365.com\/wp-content\/uploads\/2024\/04\/1902-10-20-2025-Redone-300x31.jpg 300w, https:\/\/practical365.com\/wp-content\/uploads\/2024\/04\/1902-10-20-2025-Redone-768x80.jpg 768w, https:\/\/practical365.com\/wp-content\/uploads\/2024\/04\/1902-10-20-2025-Redone.jpg 860w\" sizes=\"auto, (max-width: 861px) 100vw, 861px\" \/><\/a><\/p>\n<\/div><\/div><h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Dealing_with_Permissions\"><\/span>Dealing with Permissions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Using the <em>Send-MgUserMessage<\/em> and <em>Send-MgUserMail<\/em> cmdlets both require the <strong><em>Mail.Send<\/em><\/strong> Graph permission. Creating the draft message for <em>Send-MgUserMessage<\/em> to dispatch requires the <strong><em>Mail.ReadWrite<\/em><\/strong> permission. These permissions apply to every mailbox in the tenant. In other words, a background app equipped with these permissions that uses certificate-based authentication can write into every mailbox and send email from every mailbox. With that kind of access, care must be taken to restrict the ability of scripts running with apps or using Azure Automation runbooks (with or without <a href=\"https:\/\/practical365.com\/managed-identity-powershell\/\" target=\"_blank\" rel=\"noreferrer noopener\">a managed identity<\/a>) to access mailboxes.<\/p>\n\n\n\n<p>The right way to do that is with an <a href=\"https:\/\/practical365.com\/new-application-access-policies-extend-support-for-more-scenarios\/\" target=\"_blank\" rel=\"noreferrer noopener\">application access policy<\/a>. These policies dictate the mailboxes an app can access, meaning that you can limit apps to some app-specific mailboxes and keep them well away from user mailboxes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Decision_Time\"><\/span>Decision Time<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It\u2019s nice to have a choice. Developers who update scripts to remove the dependency on SMTP AUTH have at least four Graph-based options. For me, I think I shall use <em>Send-MgUserMail<\/em> whenever possible, if only because it\u2019s the easiest way to send a message. At least, the easiest Microsoft-based method. The independent <em>Send-EmailMessage<\/em> cmdlet looks like an attractive option too!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet and compares it to the Send-MgUserMessage cmdlet (covered in depth in a previous article). Our conclusion is that you&#8217;ll probably end up using Send0-MgUserMail because it&#8217;s easier to use.<\/p>\n","protected":false},"author":84,"featured_media":57467,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[26,9055],"tags":[10119,238,10681,10198],"class_list":["post-57352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange-online","category-powershell","tag-microsoft-graph-powershell-sdk","tag-powershell","tag-send-mgusermail","tag-send-mgusermessage","entry","has-media"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.2 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Four Ways to Send Email using PowerShell and the Microsoft Graph<\/title>\n<meta name=\"description\" content=\"For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practical365.com\/send-email-powershell-graph\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Practical Graph: Ways to Send Email via the Microsoft Graph\" \/>\n<meta property=\"og:description\" content=\"For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practical365.com\/send-email-powershell-graph\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical 365\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Practical365\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-01T10:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T11:26:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Tony Redmond\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/12Knocksinna\" \/>\n<meta name=\"twitter:site\" content=\"@Practical365\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tony Redmond\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/\"},\"author\":{\"name\":\"Tony Redmond\",\"@id\":\"https:\\\/\\\/practical365.com\\\/#\\\/schema\\\/person\\\/19d7b2f404dd1da1d87586fb07015a19\"},\"headline\":\"Practical Graph: Ways to Send Email via the Microsoft Graph\",\"datePublished\":\"2022-11-01T10:00:00+00:00\",\"dateModified\":\"2025-01-07T11:26:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/\"},\"wordCount\":1127,\"commentCount\":16,\"publisher\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg\",\"keywords\":[\"Microsoft Graph PowerShell SDK\",\"PowerShell\",\"Send-MgUserMail\",\"Send-MgUserMessage\"],\"articleSection\":[\"Exchange Online\",\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/\",\"url\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/\",\"name\":\"Four Ways to Send Email using PowerShell and the Microsoft Graph\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg\",\"datePublished\":\"2022-11-01T10:00:00+00:00\",\"dateModified\":\"2025-01-07T11:26:38+00:00\",\"description\":\"For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#primaryimage\",\"url\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg\",\"contentUrl\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg\",\"width\":1100,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practical365.com\\\/send-email-powershell-graph\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practical365.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Exchange Online\",\"item\":\"https:\\\/\\\/practical365.com\\\/exchange-online\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Practical Graph: Ways to Send Email via the Microsoft Graph\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practical365.com\\\/#website\",\"url\":\"https:\\\/\\\/practical365.com\\\/\",\"name\":\"Practical 365\",\"description\":\"Practical Office 365 News, Tips, and Tutorials\",\"publisher\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practical365.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/practical365.com\\\/#organization\",\"name\":\"Practical 365\",\"url\":\"https:\\\/\\\/practical365.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practical365.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Logo-P365-stacked.jpg\",\"contentUrl\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Logo-P365-stacked.jpg\",\"width\":1176,\"height\":696,\"caption\":\"Practical 365\"},\"image\":{\"@id\":\"https:\\\/\\\/practical365.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Practical365\",\"https:\\\/\\\/x.com\\\/Practical365\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/practical365-com\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/practical365.com\\\/#\\\/schema\\\/person\\\/19d7b2f404dd1da1d87586fb07015a19\",\"name\":\"Tony Redmond\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/cropped-TonyRedmondHeadShot2016-1200-96x96.jpg\",\"url\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/cropped-TonyRedmondHeadShot2016-1200-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/practical365.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/cropped-TonyRedmondHeadShot2016-1200-96x96.jpg\",\"caption\":\"Tony Redmond\"},\"description\":\"Tony Redmond has written thousands of articles about Microsoft technology since 1996. He is the lead author for the Office 365 for IT Pros eBook, the only book covering Office 365 that is updated monthly to keep pace with change in the cloud. Apart from contributing to Practical365.com, Tony also writes at Office365itpros.com to support the development of the eBook. He has been a Microsoft MVP since 2004.\",\"sameAs\":[\"https:\\\/\\\/office365itpros.com\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/12Knocksinna\"],\"url\":\"https:\\\/\\\/practical365.com\\\/author\\\/tony-redmondredmondassociates-org\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Four Ways to Send Email using PowerShell and the Microsoft Graph","description":"For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practical365.com\/send-email-powershell-graph\/","og_locale":"en_US","og_type":"article","og_title":"Practical Graph: Ways to Send Email via the Microsoft Graph","og_description":"For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet.","og_url":"https:\/\/practical365.com\/send-email-powershell-graph\/","og_site_name":"Practical 365","article_publisher":"https:\/\/www.facebook.com\/Practical365","article_published_time":"2022-11-01T10:00:00+00:00","article_modified_time":"2025-01-07T11:26:38+00:00","og_image":[{"width":1100,"height":500,"url":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg","type":"image\/jpeg"}],"author":"Tony Redmond","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/12Knocksinna","twitter_site":"@Practical365","twitter_misc":{"Written by":"Tony Redmond","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#article","isPartOf":{"@id":"https:\/\/practical365.com\/send-email-powershell-graph\/"},"author":{"name":"Tony Redmond","@id":"https:\/\/practical365.com\/#\/schema\/person\/19d7b2f404dd1da1d87586fb07015a19"},"headline":"Practical Graph: Ways to Send Email via the Microsoft Graph","datePublished":"2022-11-01T10:00:00+00:00","dateModified":"2025-01-07T11:26:38+00:00","mainEntityOfPage":{"@id":"https:\/\/practical365.com\/send-email-powershell-graph\/"},"wordCount":1127,"commentCount":16,"publisher":{"@id":"https:\/\/practical365.com\/#organization"},"image":{"@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#primaryimage"},"thumbnailUrl":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg","keywords":["Microsoft Graph PowerShell SDK","PowerShell","Send-MgUserMail","Send-MgUserMessage"],"articleSection":["Exchange Online","PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practical365.com\/send-email-powershell-graph\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practical365.com\/send-email-powershell-graph\/","url":"https:\/\/practical365.com\/send-email-powershell-graph\/","name":"Four Ways to Send Email using PowerShell and the Microsoft Graph","isPartOf":{"@id":"https:\/\/practical365.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#primaryimage"},"image":{"@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#primaryimage"},"thumbnailUrl":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg","datePublished":"2022-11-01T10:00:00+00:00","dateModified":"2025-01-07T11:26:38+00:00","description":"For those wanting to eliminate the SMTP AUTH protocol, Microsoft has three ways to send email using Graph APIs. This article looks at how to use the Send-MgUserMail cmdlet.","breadcrumb":{"@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practical365.com\/send-email-powershell-graph\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#primaryimage","url":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg","contentUrl":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/10\/663-10-17-2022-The-many-ways-to-send-email-with-the-Microsoft-Graph-LOW.jpg","width":1100,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/practical365.com\/send-email-powershell-graph\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practical365.com\/"},{"@type":"ListItem","position":2,"name":"Exchange Online","item":"https:\/\/practical365.com\/exchange-online\/"},{"@type":"ListItem","position":3,"name":"Practical Graph: Ways to Send Email via the Microsoft Graph"}]},{"@type":"WebSite","@id":"https:\/\/practical365.com\/#website","url":"https:\/\/practical365.com\/","name":"Practical 365","description":"Practical Office 365 News, Tips, and Tutorials","publisher":{"@id":"https:\/\/practical365.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practical365.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/practical365.com\/#organization","name":"Practical 365","url":"https:\/\/practical365.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practical365.com\/#\/schema\/logo\/image\/","url":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/06\/Logo-P365-stacked.jpg","contentUrl":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/06\/Logo-P365-stacked.jpg","width":1176,"height":696,"caption":"Practical 365"},"image":{"@id":"https:\/\/practical365.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Practical365","https:\/\/x.com\/Practical365","https:\/\/www.linkedin.com\/company\/practical365-com"]},{"@type":"Person","@id":"https:\/\/practical365.com\/#\/schema\/person\/19d7b2f404dd1da1d87586fb07015a19","name":"Tony Redmond","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/06\/cropped-TonyRedmondHeadShot2016-1200-96x96.jpg","url":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/06\/cropped-TonyRedmondHeadShot2016-1200-96x96.jpg","contentUrl":"https:\/\/practical365.com\/wp-content\/uploads\/2022\/06\/cropped-TonyRedmondHeadShot2016-1200-96x96.jpg","caption":"Tony Redmond"},"description":"Tony Redmond has written thousands of articles about Microsoft technology since 1996. He is the lead author for the Office 365 for IT Pros eBook, the only book covering Office 365 that is updated monthly to keep pace with change in the cloud. Apart from contributing to Practical365.com, Tony also writes at Office365itpros.com to support the development of the eBook. He has been a Microsoft MVP since 2004.","sameAs":["https:\/\/office365itpros.com","https:\/\/x.com\/https:\/\/twitter.com\/12Knocksinna"],"url":"https:\/\/practical365.com\/author\/tony-redmondredmondassociates-org\/"}]}},"_links":{"self":[{"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/posts\/57352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/users\/84"}],"replies":[{"embeddable":true,"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/comments?post=57352"}],"version-history":[{"count":0,"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/posts\/57352\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/media\/57467"}],"wp:attachment":[{"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/media?parent=57352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/categories?post=57352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practical365.com\/wp-json\/wp\/v2\/tags?post=57352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}