Showing posts with label Mail Flow. Show all posts
Showing posts with label Mail Flow. Show all posts

Friday, March 15, 2024

[O365] Send email in O365 via Powershell

 

$Recipient = "contact@domain.com"

$Subject = "Hello, World!"

$Body = "This is the body of the email."

$credentials = Get-Credential

Send-MailMessage -To $Recipient -Subject $subject -Body $body -From $credentials.UserName -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $credentials


-----------------


Using saved/exported password:


# $credentials.Password | ConvertFrom-SecureString | out-file  L:\Downloads\senha.sec

$sen = Get-Content L:\Downloads\senha.sec | ConvertTo-SecureString

$us = "sender@mydomain.com"

$em = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $us,$sen

Send-MailMessage -To $Recipient -Subject $subject -Body $body -From $us -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $em

Wednesday, November 1, 2023

[O365] Collect more than 1000 results in Message Trace

 $P = 1

$messages = $null

do

{

Write-Host “Message Trace – Page $P…”

$temp_Messages = Get-MessageTrace -startdate "09/12/2022 12:00:00 AM" -Enddate "09/12/2022 06:00:00 PM" -PageSize 1000 -Page $P

$P++

$Messages += $temp_Messages

}until ($temp_Messages -eq $null)


#display messages

$Messages.Count

$Messages

Monday, March 30, 2020

[O365] Export reports for quarantined messages



Get-QuarantineMessage | select ReceivedTime,SenderAddress,RecipientAddress,Subject,Type,SystemReleased,PolicyType,Expires | Export-CSV -NoTypeInformation “c:/reports.csv”

Tuesday, January 19, 2016

[EX2010] Script to send test messages


To open connectors:

Get-ReceiveConnector |?{$_.Name -like "*defa*"} | Set-ReceiveConnector -PermissionGroups 'AnonymousUsers, ExchangeUsers, ExchangeServers, ExchangeLegacyServers'


To send test messages:

$domain = (Get-AcceptedDomain).name
$fqdn = "$env:computername.$env:userdnsdomain"
$date = Get-Date -UFormat "%m/%d/%Y"
$mbx = Get-Mailbox -RecipientTypeDetails UserMailbox
$tot = read-host "Messages per user"

while ($val -ne $tot) {$val++ ; $mbx | % -Process {Send-MailMessage -To $_.PrimarySmtpAddress -From noreply@$domain -Subject "Test Message from $date - Message # $val" -Body "Please don't reply this message. We are making some tests in our Exchange environment" -SmtpServer $fqdn}}