Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created July 8, 2020 17:52
Show Gist options
  • Save ThabetAmer/8dda6a748b88a4c35e12c6884e867400 to your computer and use it in GitHub Desktop.
Save ThabetAmer/8dda6a748b88a4c35e12c6884e867400 to your computer and use it in GitHub Desktop.
Enables SMTP Auth for Office365 emails
#
# Enables SMTP Auth for Office365 emails, so you can send emails via a script for application.
# Shall be run via Powershell terminal.
#
# Define your email address that will send emails via SMTP auth
$emailAddress = '[email protected]'
# asks for email/password
$UserCredential = Get-Credential
# creates basic auth session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange \
-ConnectionUri https://outlook.office365.com/powershell-liveid/
-Credential $UserCredential -Authentication Basic -AllowRedirection
# initiates the session
Import-PSSession $Session -DisableNameChecking
# enables SMTP auth
Set-CASMailbox -Identity $emailAddress -SmtpClientAuthenticationDisabled $false
# verifies the action, shall be set as False
Get-CASMailbox -Identity $emailAddress | Format-List SmtpClientAuthenticationDisabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment