{"id":6206,"date":"2022-09-29T05:28:55","date_gmt":"2022-09-29T05:28:55","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=6206"},"modified":"2026-05-12T06:19:58","modified_gmt":"2026-05-12T06:19:58","slug":"using-powershell-to-send-emails-via-365","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365","title":{"rendered":"Using Powershell to Send Emails via 365"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1\">https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"282\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image-1024x282.png\" alt=\"\" class=\"wp-image-7877 img-responsive\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image-1024x282.png 1024w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image-300x83.png 300w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image-768x212.png 768w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image.png 1452w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$clientID = \"XXXXXXXXXXX\"\n$Clientsecret = \"XXXXXXXXXXX\"\n$tenantID = \"XXXXXXXXXXX\"\n\n$MailSender = \"test@test.com\"\n\n#Connect to GRAPH API\n$tokenBody = @{\n    Grant_Type    = \"client_credentials\"\n    Scope         = \"https:\/\/graph.microsoft.com\/.default\"\n    Client_Id     = $clientId\n    Client_Secret = $clientSecret\n}\n$tokenResponse = Invoke-RestMethod -Uri \"https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token\" -Method POST -Body $tokenBody\n$headers = @{\n    \"Authorization\" = \"Bearer $($tokenResponse.access_token)\"\n    \"Content-type\"  = \"application\/json\"\n}\n\n#Send Mail    \n$URLsend = \"https:\/\/graph.microsoft.com\/v1.0\/users\/$MailSender\/sendMail\"\n$BodyJsonsend = @\"\n                    {\n                        \"message\": {\n                          \"subject\": \"Hello World from Microsoft Graph API\",\n                          \"body\": {\n                            \"contentType\": \"HTML\",\n                            \"content\": \"This Mail is sent via Microsoft &lt;br&gt;\n                            GRAPH &lt;br&gt;\n                            API&lt;br&gt;\n                            \n                            \"\n                          },\n                          \"toRecipients\": [\n                            {\n                              \"emailAddress\": {\n                                \"address\": \"test@test.com\"\n                              }\n                            }\n                          ]\n                        },\n                        \"saveToSentItems\": \"false\"\n                      }\n\"@\n\nInvoke-RestMethod -Method POST -Uri $URLsend -Headers $headers -Body $BodyJsonsend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SMTP Will be Decommed Soon ( Below ) <\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Make sure the account has an Exchange License<\/li>\n\n\n\n<li>Turn Security Default Off&nbsp;<br><img loading=\"lazy\" decoding=\"async\" width=\"1653\" height=\"405\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352c68bc961.png\" alt=\"\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352c68bc961.png 1653w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352c68bc961-300x74.png 300w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352c68bc961-1024x251.png 1024w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352c68bc961-768x188.png 768w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352c68bc961-1536x376.png 1536w\"><\/li>\n\n\n\n<li>Create an App Password for the account. MFA and Modern auth will Obviously be enabled for the account so you won\u2019t be able to use thatIn Azure AD&nbsp;<img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"208\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352bb2d1713.png\" alt=\"\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352bb2d1713.png 598w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352bb2d1713-300x104.png 300w\">Get App Password for account<br><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"217\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352833aa1fc.png\" alt=\"\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352833aa1fc.png 600w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352833aa1fc-300x109.png 300w\"><br><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"216\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_6335283f9e87d.png\" alt=\"\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_6335283f9e87d.png 404w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_6335283f9e87d-300x160.png 300w\"><br><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"206\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352852d638c.png\" alt=\"\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352852d638c.png 470w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2022\/09\/img_63352852d638c-300x131.png 300w\"><\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log into your Office 365 Admin account<\/li>\n\n\n\n<li>Click the Green HELP &amp; SUPPORT button in the bottom left corner<\/li>\n\n\n\n<li>In the search bar, type:&nbsp; Diag: Enable Basic Auth in EXO<\/li>\n\n\n\n<li>Click the Blue arrow to search<\/li>\n\n\n\n<li>Click the RUN TESTS button<\/li>\n\n\n\n<li>Once the tests are done, select SMTP in the Protocol to Opt Out dropdown.<\/li>\n\n\n\n<li>Click the check box below it.<\/li>\n\n\n\n<li>Click the UPDATE SETTINGS button<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">#New Security Policy\n\nNew-AuthenticationPolicy -Name \"Allow Basic Auth for SMTP\"\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthWebServices:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthOutlookService:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthReportingWebServices:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthActiveSync:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthRest:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthPowershell:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthMapi:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthOfflineAddressBook:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthAutodiscover:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthRpc:$false\nSet-AuthenticationPolicy -Identity \"Allow Basic Auth for SMTP\" -AllowBasicAuthSmtp:$true\n\n\n#Apply Security Policy \n\nSet-User -Identity smtp@domain.com -AuthenticationPolicy \"Allow Basic Auth for SMTP\"\n\n#Turn on SMTP AUTH\n\nSet-CASMailbox -Identity smtp@domain.com -SmtpClientAuthenticationDisabled $false<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\"># Enable TLS 1.2 as Security Protocol\n[Net.ServicePointManager]::SecurityProtocol = `\n    [Net.SecurityProtocolType]::Tls12 ;\n\n#Username is UPN \\ Email\n#APP Password for password\n\n$creds = Get-Credential\n\nSend-MailMessage -From smtp@domain.com -To test@test.com -Subject \"Test Email\" -Body \"Test SMTP Service from Powershell on Port 587\" -SmtpServer smtp.office365.com -Credential $creds -Usessl -Port 587<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\"># Parameters\n$fromEmail = \"XXXXXXXXX\"  # Your Office 365 email\n$toEmail = \"XXXXXXXXX\"     # Recipient's email\n$subject = \"Test Email via SMTP\"\n$body = \"This is a test email sent from PowerShell using an HVE account.\"\n$smtpServer = \"smtp.hve.mx.microsoft\"\n$smtpPort = 587\n$username = \"XXXXXXXXX\"   # Your Office 365 email\n\n$password = \"XXXXXXXXX\"  # Use app password if MFA is enabled, or regular password if basic auth is allowed\n\n\n\n# Create credentials\n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credentials = New-Object System.Management.Automation.PSCredential ($username, $securePassword)\n\n\n\n\ntry {\n    # Send email using Send-MailMessage\n    Send-MailMessage `\n        -From $fromEmail `\n        -To $toEmail `\n        -Subject $subject `\n        -Body $body `\n        -SmtpServer $smtpServer `\n        -Port $smtpPort `\n        -UseSsl `\n        -Credential $credentials `\n        -ErrorAction Stop\n\n    Write-Host \"Email sent successfully!\" -ForegroundColor Green\n}\ncatch {\n    Write-Host \"Error sending email: $_\" -ForegroundColor Red\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 SMTP Will be Decommed Soon ( Below )<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1206,2780,4007,4006,576,1176],"class_list":["post-6206","post","type-post","status-publish","format-standard","hentry","category-research","tag-1206","tag-auth","tag-mfp","tag-office365","tag-powershell","tag-smtp"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"description\" content=\"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = &quot;XXXXXXXXXXX&quot; $Clientsecret = &quot;XXXXXXXXXXX&quot; $tenantID = &quot;XXXXXXXXXXX&quot; $MailSender = &quot;test@test.com&quot; #Connect to GRAPH API $tokenBody = @{ Grant_Type = &quot;client_credentials&quot; Scope = &quot;https:\/\/graph.microsoft.com\/.default&quot; Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri &quot;https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token&quot; -Method\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"paris\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Welcome to Pariswells.com |\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com\" \/>\n\t\t<meta property=\"og:description\" content=\"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = &quot;XXXXXXXXXXX&quot; $Clientsecret = &quot;XXXXXXXXXXX&quot; $tenantID = &quot;XXXXXXXXXXX&quot; $MailSender = &quot;test@test.com&quot; #Connect to GRAPH API $tokenBody = @{ Grant_Type = &quot;client_credentials&quot; Scope = &quot;https:\/\/graph.microsoft.com\/.default&quot; Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri &quot;https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token&quot; -Method\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-09-29T05:28:55+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-05-12T06:19:58+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = &quot;XXXXXXXXXXX&quot; $Clientsecret = &quot;XXXXXXXXXXX&quot; $tenantID = &quot;XXXXXXXXXXX&quot; $MailSender = &quot;test@test.com&quot; #Connect to GRAPH API $tokenBody = @{ Grant_Type = &quot;client_credentials&quot; Scope = &quot;https:\/\/graph.microsoft.com\/.default&quot; Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri &quot;https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token&quot; -Method\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#article\",\"name\":\"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com\",\"headline\":\"Using Powershell to Send Emails via 365\",\"author\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/image-1024x282.png\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365\\\/#articleImage\"},\"datePublished\":\"2022-09-29T05:28:55+00:00\",\"dateModified\":\"2026-05-12T06:19:58+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#webpage\"},\"articleSection\":\"Research, 365, auth, MFP, office365, powershell, smtp\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/pariswells.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research#listItem\",\"name\":\"Research\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research#listItem\",\"position\":2,\"name\":\"Research\",\"item\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#listItem\",\"name\":\"Using Powershell to Send Emails via 365\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#listItem\",\"position\":3,\"name\":\"Using Powershell to Send Emails via 365\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research#listItem\",\"name\":\"Research\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#organization\",\"name\":\"Welcome to Pariswells.com\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris\",\"name\":\"paris\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/93b8ee3f592ac401167f870452bd82d43de80152cd3524e2853403658ada9984?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"paris\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#webpage\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365\",\"name\":\"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com\",\"description\":\"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\\\/\\\/github.com\\\/richfaj\\\/SmtpClientDiag\\\/blob\\\/master\\\/SmtpClientDiag.psm1 $clientID = \\\"XXXXXXXXXXX\\\" $Clientsecret = \\\"XXXXXXXXXXX\\\" $tenantID = \\\"XXXXXXXXXXX\\\" $MailSender = \\\"test@test.com\\\" #Connect to GRAPH API $tokenBody = @{ Grant_Type = \\\"client_credentials\\\" Scope = \\\"https:\\\/\\\/graph.microsoft.com\\\/.default\\\" Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri \\\"https:\\\/\\\/login.microsoftonline.com\\\/$tenantID\\\/oauth2\\\/v2.0\\\/token\\\" -Method\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/using-powershell-to-send-emails-via-365#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\"},\"datePublished\":\"2022-09-29T05:28:55+00:00\",\"dateModified\":\"2026-05-12T06:19:58+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/\",\"name\":\"Welcome to Pariswells.com\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com","description":"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = \"XXXXXXXXXXX\" $Clientsecret = \"XXXXXXXXXXX\" $tenantID = \"XXXXXXXXXXX\" $MailSender = \"test@test.com\" #Connect to GRAPH API $tokenBody = @{ Grant_Type = \"client_credentials\" Scope = \"https:\/\/graph.microsoft.com\/.default\" Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri \"https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token\" -Method","canonical_url":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#article","name":"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com","headline":"Using Powershell to Send Emails via 365","author":{"@id":"https:\/\/pariswells.com\/blog\/author\/paris#author"},"publisher":{"@id":"https:\/\/pariswells.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2024\/05\/image-1024x282.png","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365\/#articleImage"},"datePublished":"2022-09-29T05:28:55+00:00","dateModified":"2026-05-12T06:19:58+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#webpage"},"isPartOf":{"@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#webpage"},"articleSection":"Research, 365, auth, MFP, office365, powershell, smtp"},{"@type":"BreadcrumbList","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/pariswells.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/category\/research#listItem","name":"Research"}},{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/category\/research#listItem","position":2,"name":"Research","item":"https:\/\/pariswells.com\/blog\/category\/research","nextItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#listItem","name":"Using Powershell to Send Emails via 365"},"previousItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#listItem","position":3,"name":"Using Powershell to Send Emails via 365","previousItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/category\/research#listItem","name":"Research"}}]},{"@type":"Organization","@id":"https:\/\/pariswells.com\/blog\/#organization","name":"Welcome to Pariswells.com","url":"https:\/\/pariswells.com\/blog\/"},{"@type":"Person","@id":"https:\/\/pariswells.com\/blog\/author\/paris#author","url":"https:\/\/pariswells.com\/blog\/author\/paris","name":"paris","image":{"@type":"ImageObject","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/93b8ee3f592ac401167f870452bd82d43de80152cd3524e2853403658ada9984?s=96&d=mm&r=g","width":96,"height":96,"caption":"paris"}},{"@type":"WebPage","@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#webpage","url":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365","name":"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com","description":"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = \"XXXXXXXXXXX\" $Clientsecret = \"XXXXXXXXXXX\" $tenantID = \"XXXXXXXXXXX\" $MailSender = \"test@test.com\" #Connect to GRAPH API $tokenBody = @{ Grant_Type = \"client_credentials\" Scope = \"https:\/\/graph.microsoft.com\/.default\" Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri \"https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token\" -Method","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/pariswells.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365#breadcrumblist"},"author":{"@id":"https:\/\/pariswells.com\/blog\/author\/paris#author"},"creator":{"@id":"https:\/\/pariswells.com\/blog\/author\/paris#author"},"datePublished":"2022-09-29T05:28:55+00:00","dateModified":"2026-05-12T06:19:58+00:00"},{"@type":"WebSite","@id":"https:\/\/pariswells.com\/blog\/#website","url":"https:\/\/pariswells.com\/blog\/","name":"Welcome to Pariswells.com","inLanguage":"en-US","publisher":{"@id":"https:\/\/pariswells.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Welcome to Pariswells.com |","og:type":"article","og:title":"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com","og:description":"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = &quot;XXXXXXXXXXX&quot; $Clientsecret = &quot;XXXXXXXXXXX&quot; $tenantID = &quot;XXXXXXXXXXX&quot; $MailSender = &quot;test@test.com&quot; #Connect to GRAPH API $tokenBody = @{ Grant_Type = &quot;client_credentials&quot; Scope = &quot;https:\/\/graph.microsoft.com\/.default&quot; Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri &quot;https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token&quot; -Method","og:url":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365","article:published_time":"2022-09-29T05:28:55+00:00","article:modified_time":"2026-05-12T06:19:58+00:00","twitter:card":"summary","twitter:title":"Using Powershell to Send Emails via 365 | Welcome to Pariswells.com","twitter:description":"Finally can do this via OAuth ( No Username and password Azure APP ) AND Non-Interactive https:\/\/github.com\/richfaj\/SmtpClientDiag\/blob\/master\/SmtpClientDiag.psm1 $clientID = &quot;XXXXXXXXXXX&quot; $Clientsecret = &quot;XXXXXXXXXXX&quot; $tenantID = &quot;XXXXXXXXXXX&quot; $MailSender = &quot;test@test.com&quot; #Connect to GRAPH API $tokenBody = @{ Grant_Type = &quot;client_credentials&quot; Scope = &quot;https:\/\/graph.microsoft.com\/.default&quot; Client_Id = $clientId Client_Secret = $clientSecret } $tokenResponse = Invoke-RestMethod -Uri &quot;https:\/\/login.microsoftonline.com\/$tenantID\/oauth2\/v2.0\/token&quot; -Method"},"aioseo_meta_data":{"post_id":"6206","title":null,"description":null,"keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":[],"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2022-09-29 05:06:05","updated":"2026-05-12 06:19:58","primary_term":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/pariswells.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/pariswells.com\/blog\/category\/research\" title=\"Research\">Research<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUsing Powershell to Send Emails via 365\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/pariswells.com\/blog"},{"label":"Research","link":"https:\/\/pariswells.com\/blog\/category\/research"},{"label":"Using Powershell to Send Emails via 365","link":"https:\/\/pariswells.com\/blog\/research\/using-powershell-to-send-emails-via-365"}],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=6206"}],"version-history":[{"count":8,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6206\/revisions"}],"predecessor-version":[{"id":9642,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6206\/revisions\/9642"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=6206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=6206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=6206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}