Send-MailForMe

Use Outlook to send a message from your mailbox in your name and updates the Outlook security settings if needed

<#
.SYNOPSIS
    Send-MailForMe.ps1 - Use Outlook to send a message from your mailbox
.DESCRIPTION
    Send-MailForMe - Use Outlook to send a message from your mailbox in your name
    Updates the Outlook security settings if needed
.NOTES
    File Name   : Send-MailForMe.ps1
    Author      : Fabrice ZERROUKI - fabricezerrouki@hotmail.com
.EXAMPLE
    PS D:\> .\Send-MailForMe.ps1
#>
Write-Host "`nChecking if Outlook is running" -ForegroundColor DarkGreen;
if (Get-Process -ErrorAction "SilentlyContinue" | Where {$_.ProcessName -eq "Outlook"})
{
Start-Sleep 1
Write-Host "Killing Outlook to update its settings" -ForegroundColor DarkGreen;
Stop-Process -ProcessName Outlook
}
# Checks if the registry key exists, if not creates it
if (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security"))
{
Write-Host "Updating Outlook security settings" -ForegroundColor DarkGreen;
New-Item -Path HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook -Name Security
}
# Checks if the dword value exists, if yes sets its value and if not creates it
if (!(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security -Name ObjectModelGuard))
{
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security" -Name "ObjectModelGuard" -Value 00000002 -PropertyType "DWord"
} else {Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Office\14.0\Outlook\Security" -Name "ObjectModelGuard" -Value 00000002}
# Checks if the registry key exists, if not creates it
if (!(Test-Path "HKCU:\Software\Microsoft\Office\14.0\Outlook\Security"))
{
Write-Host "Updating Outlook security settings (again)" -ForegroundColor DarkGreen;
New-Item -Path HKCU:\Software\Microsoft\Office\14.0\Outlook -Name Security
}
# Checks if the dword value exists, if yes sets its value and if not creates it
if (!(Get-ItemProperty -Path HKCU:\Software\Microsoft\Office\14.0\Outlook\Security -Name PromptOOMSend))
{
New-ItemProperty "HKCU:\Software\Microsoft\Office\14.0\Outlook\Security" -Name "PromptOOMSend" -Value 00000002 -PropertyType "DWord"
} else {Set-ItemProperty "HKCU:\Software\Microsoft\Office\14.0\Outlook\Security" -Name "PromptOOMSend" -Value 00000002}

# Checks if the dword value exists, if yes sets its value and if not creates it
if (!(Get-ItemProperty -Path HKCU:\Software\Microsoft\Office\14.0\Outlook\Security -Name AdminSecurityMode))
{
New-ItemProperty "HKCU:\Software\Microsoft\Office\14.0\Outlook\Security" -Name "AdminSecurityMode" -Value 00000003 -PropertyType "DWord"
} else {Set-ItemProperty "HKCU:\Software\Microsoft\Office\14.0\Outlook\Security" -Name "AdminSecurityMode" -Value 00000003}
Write-Host "Outlook settings updated" -ForegroundColor DarkGreen;
Start-Sleep 1
Write-Host "Opening Outlook to send your message" -ForegroundColor DarkGreen;
$Outlook=New-Object -comObject Outlook.Application
$Namespace = $outlook.GetNamespace("MAPI")
$Folder = $namespace.GetDefaultFolder("olFolderInbox")
$Explorer = $folder.GetExplorer()
$Explorer.Display()
$Mail=$Outlook.CreateItem(0) 
$Mail.Recipients.Add('recipient@mail.com') | Out-Null
$Mail.Subject="Subject" 
$Mail.HTMLBody=@"
This body <u>is</u> in <strong>HTML</strong>
"@
$Mail.Send()
Write-Host "Message sent!`n" -ForegroundColor DarkGreen;

To be scheduled late in the evening if you want your boss to believe you really love your job! 😉

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top