Wednesday, May 22, 2019

Emails going into Draft in a On-premises environment

The problem

You are using OWA or outlook to send your emails (your mail server is an on-premises Exchange server) and all the emails are going into the Draft folder of the user.

The Solution

1. Check the Local services using the Services.msc or services console to make sure that all the exchange servers are set to automatic and are running.

https://msexperttalk.com/exchange-2013-email-stuck-in-draft/ https://www.exchangeitpro.com/2016/06/13/exchange-server-2013-components-in-an-inactive-state/ https://gallery.technet.microsoft.com/exchange/SetExchangeComponentToActiv-874bcd4b

a. Open a Powershell for exchange or simple powershell with administrative privilegies (using Run as Administrator):

 

b. Run my script from technet at https://gallery.technet.microsoft.com/office/What-is-the-size-of-my-0e1993a7 to check Database (.EDB file) and and Logs size in the server

The correct way to run the script will be as follows

#Change Executionpolicy,
Set-ExecutionPolicy unrestricted
#Run the script (move to the folder where the script is downloaded) 
#Ex: in the downloads of the user 'joseo'
cd "C:\Users\joseo\Downloads"
.\ExchangeDBnLogsize.ps1

You will get something like this:

Note: Please Do not modify the edgetransport.exe.config file, it's a bad practice, and it's just a workaround NOT a solution

 

2. Enable circular logs on the Exchange Server databases

The Easiest way to check if your server has enabled or not this feature, open an exchange PowerShell console and run:

#mail server name (On-premises exchange)
$smtpServer= "mail"
#email from can exists or not onprem
$from = "abc@xyz.com"
#to email (must exists, so you can receive the email)
$to = "jose@domain.com"
$event =Get-EventLog -Log "MSExchange Management" | Where{$_.Message -Like "*Enable-Mailbox*"} | select -first 1 

if($event){
    $MailBodyString= $event | ConvertTo-Html 
    #WE CAN'T ATTACH THE FULL THML INTO THE FILE DIRECTLY SO WE NEED TO USE THE TEXT IN THE MIDDLE OF THE  AND 
TAGS WHICH IS DONE USING REGEX #all the results are dump into a table tags so we extract those. $regex = new-object regex('(?s)(< table>(.*)<\</table>)', ([System.Text.RegularExpressions.RegexOptions]::Compiled -bor [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)) $MailBodyAsHtml = $Regex.Match($MailBodyString).VALUE Send-MailMessage -From $from -To $to -Subject "New Account created" -Body $MailBodyAsHtml -SmtpServer $smtpServer -BodyAsHtml }

 

And that's it!, thank you for reading

#when you got the results just return the executionpolicy #(when you finished working with powershell scripts, as a good practice ) Set-ExecutionPolicy remotesigned

Please consider to donate and thank you very much for reading this.

Send an email on HTML format with the information of the latest New Mailbox created on your exchange server

The problem

Send an email with the latest mailbox created in your exchange server and email it to sombody

 

 

The Solution

Over a PowerShell script to

a. Open a Powershell for exchange or simple powershell with administrative privilegies (using Run as Administrator):

&nbsp

It can be done using this following commands

The correct way to run the script will be as follows
#name of the server (exchange server on-premises)
$smtpServer= "mail" 
#from address where you want to receive the email, can exist or not
$from = "abc@xyz.com"
#your email address (must exists, so you can actually receive the email
$to = "jose@domain.com"
$event =Get-EventLog -Log "MSExchange Management" | Where{$_.Message -Like "*Enable-Mailbox*"} | select -first 1 

if($event){
    $MailBodyString= $event | ConvertTo-Html 
    #WE CAN'T ATTACH THE FULL THML INTO THE FILE DIRECTLY SO WE NEED TO USE THE TEXT IN THE MIDDLE OF THE tables tags 
TAGS WHICH IS DONE USING REGEX
    $regex = new-object regex('(?s)(<table>(.*)<\/table>)', ([System.Text.RegularExpressions.RegexOptions]::Compiled -bor [System.Text.RegularExpressions.RegexOptions]::IgnoreCase))
    $MailBodyAsHtml = $Regex.Match($MailBodyString).VALUE
    Send-MailMessage -From $from -To $to -Subject "New Account created" -Body $MailBodyAsHtml -SmtpServer $smtpServer -BodyAsHtml
}
You will get an email in HTML format with the last event information And that's it! thank you for reading
Please consider to donate and thank you very much for reading this.

Tuesday, May 21, 2019

Get a list of all domains where you have received emails on the last 60 days

The problem

How can I get a list of all domains that I've received email from in the last 2 months

 

 

The Solution

Over a PowerShell script to

a. Open a Powershell for exchange or simple powershell with administrative privilegies (using Run as Administrator):

 

It can be done using this following commands

The correct way to run the script will be as follows
#Change Executionpolicy (just in case you haven't done this already),
Set-ExecutionPolicy unrestricted
#Accept the warning (by pressing Y or A then press enter)

#Run the script (move to the folder where the script is downloaded) 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
$localdomain= "mydomain.com" # local domain public to be excluded on the search
Get-MessageTrackingLog -Server Mail -Start $( (Get-Date).ADddays(-60) ) -End $( Get-Date) -ResultSize Unlimited | select Recipients,EventId | where { ($_.EventId -eq "RECEIVE") -and $_.Recipients -notmatch "HealthMailbox*"}  | select -ExpandProperty Recipients | where{ $_ -notmatch $localdomain} | %{ $_.Split('@')[1]} | select -Unique
You will get the list of all unique domains list on the screen, if you want to have them in another format you can pipe
#Run the script (move to the folder where the script is downloaded) 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
$localdomain= "mydomain.com" # local domain public to be excluded on the search
Get-MessageTrackingLog -Server Mail -Start $( (Get-Date).ADddays(-60) ) -End $( Get-Date) -ResultSize Unlimited | select Recipients,EventId | where { ($_.EventId -eq "RECEIVE") -and $_.Recipients -notmatch "HealthMailbox*"}  | select -ExpandProperty Recipients | where{ $_ -notmatch $localdomain} | %{ $_.Split('@')[1]} | select -Unique | Out-File domains.txt
And that's it! thank you for reading

Please consider to donate and thank you very much for reading this.