Tag Archives: Forward Mail

Manage Office 365 Forward Mail in PowerShell

Manage Forward Mail by using PowerShell | Office 365

<#

this script set Automatic mail Forwarding to Recipient in office 365

#>

#start script

##########################

#$user=’internal user idestity’ #the source internal user to forward emails from
#$destemail=’internal user email destination address’ #internal destination user to forward emails to
#$destemailext=’xxx@gmail.com’ #external destination email address to forward emails to
#$DisplayName’MailContact Display Name’ #MailContact Display Name
#$mailintext=’Office 365 User Email ‘ #<Office 365 User Email Address for external user (MailContact)

##########################

#Connect to Exchange Online Office 365 using remote PowerShell
#$UserCredential = Get-Credential
#$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
#Import-PSSession $Session

##########################

#Forward Email to internal Recipient & DONT saves local copy
#Set-Mailbox $user -ForwardingAddress $destemail -DeliverToMailboxAndForward $False

##########################

#Forward Email to internal Recipient & save local copy (Default)
#Set-Mailbox $user -ForwardingAddress $destemail

##########################

#Forward Email to External Recipient & save local copy (Default)
#Set-Mailbox $user -ForwardingsmtpAddress $destemailext

##########################

#Forward Email to External Recipient & DONT saves local copy
#Set-Mailbox $user -ForwardingsmtpAddress $destemailext -DeliverToMailboxAndForward $False

##########################

#Create External contact with internal email address + Forward email address (External Email Address)
#Step 1: Create External contact with External email address
#New-MailContact -Name $DisplayName -ExternalEmailAddress $destemailext
#Step 2: Set External contact email address to internal email address and forwarding email address (External email address) PowerShell command syntax:
#New-MailContact $DisplayName -emailaddresses SMTP:$mailintext, $destemailext

##########################

#Display information about Forwarding rule
#Get-Mailbox $user

##########################

#Display more information about Forwarding rule
#Get-Mailbox John | FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress

##########################

#Find all users with Forwarding Address is set to Internal Recipient
#Get-Mailbox | Where {$_.ForwardingAddress -ne $Null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward

##########################

#Turn off Email Automatic Forwarding to internal Recipient
#Set-Mailbox $user -ForwardingAddress $Null

##########################

#Turn off email Automatic Forwarding to External Recipient
#Set-Mailbox $user -ForwardingSmtpAddress $Null

##########################

#Forward Email of ALL Users to internal Recipient & save local copy
#Step 1: Save local copy
#Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”}| Set-Mailbox -DeliverToMailboxAndForward $True
#Step 2: Forward email to the destination recipient (internal\organization recipient)
#Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”}| Set-Mailbox -ForwardingAddress $destemail

##########################

#Forward Email of ALL Users to External Recipient & save local copy
#Step 1: Save local copy
#Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”}| Set-Mailbox -DeliverToMailboxAndForward $True
#Step 2: Forward email to the destination recipient (external recipient)
#Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”}| Set-Mailbox -ForwardingSmtpAddress $destemailext

##########################

#Turn off email Automatic Forwarding to External Recipient
#Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”}| Set-Mailbox -ForwardingAddress $Null

##########################

#verify that the email is set to forword
#Get-Mailbox $user| FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress

##########################

#end Exchange Online Office 365 remote PowerShell Session
#Remove-PSSession $Session

#end script