$sender = "info@domain.com";#needs to be configured in Outlook
function Invoke-SetProperty {
param(
[__ComObject] $Object,
[String] $Property,
$Value
)
[Void] $Object.GetType().InvokeMember($Property,"SetProperty",$NULL,$Object,$Value)
}
$Config = Get-Content -Path "C:\_DEV\config.txt"|ForEach-Object -Process { #adjust the file path and name
$Config = $_;
$ConfigArray = $Config.Split("_");
$Name=$ConfigArray['0'].Trim();
$Value=$ConfigArray['1'].Trim();
if($Name -eq "DateTime"){$DateTime = $Value};
if($Name -eq "TimeZone"){$TimeZone = $Value};
if($Name -eq "EstTime"){$EstTime = $Value};
if($Name -eq "EnvAffected"){$EnvAffected = $Value};
if($Name -eq "Services"){$Services = $Value};
$Subject = "Maintenance Window $DateTime "+ $TimeZone;
}
$htmltext = "<!DOCTYPE html><HTML><HEAD><STYLE>/* .ram{border:1px; background-color: rgb(255, 255, 255); border-color: #CCCCCC; border-style: solid; margin:auto; width: 600px; height:fit-content; padding: 40px; padding-top: 60px; padding-bottom: 60px; padding:'0';}*/ .nadpis1{font-family: Verdana; font-size: 22px; font-stretch: expanded; letter-spacing: 0px; word-spacing: 0px; color: #000000; margin:auto; text-align:left; font-weight: 400; text-decoration: none; font-style: normal; padding-bottom:30px;}.nadpis2{font-family: Verdana; font-size: 16px; letter-spacing: 0px; word-spacing: 1px; color: #000000; font-weight: 100; text-decoration: none; font-style: normal;}.nadpis3{font-family: Verdana; font-size: 12px; letter-spacing: 0px; word-spacing: 2px; color: #cccccc; font-weight: 100; text-decoration: none; font-style: normal;}.hodnota{color:rgb(0, 0, 0); font-family: Verdana; font-size: 12px; letter-spacing: 0px; word-spacing: 0px; font-weight: 150; text-decoration: none; font-style: normal;}.notification{font-family: Verdana; font-size: 12px; letter-spacing: 0px; word-spacing: 0px; color: #000000; font-weight: 100; text-decoration: none; font-style: normal;}table{border: 1px solid #CCCCCC; margin:auto; margin-top: 40px; width: 600px; height:fit-content; border-spacing: 20px; padding-left: 20px; padding-right: 20px; padding-bottom: 20px; padding-top: 40px; /* padding: 40px; padding-top: 40px; padding-bottom: 40px;*/}tr, th, td{height:fit-content; /*border: 1px solid #CCCCCC;*/}</style></HEAD><BODY> <CENTER> <TABLE class='table'> <tr><td><H1 class='nadpis1'>Scheduled Maintenance</H1><p class='nadpis2'>Upcoming scheduled maintenance notice</p><p class='notification'>This notice is to inform you that we will be performing scheduled maintenance that will affect the availability of <span style='color:rgb(0, 0, 0);font-weight:150px'>Axess & Axtract services</span>.</p></td></tr><tr><td><p class='notification'>Impact:<br/>During the execution of the scheduled activity, customer will experience the inability to establish a data session. No customer intervention is required.</p></td></tr><tr><td><h3 class='nadpis3'>Start time</h3><p class='hodnota'>DateTime</p></td></tr><tr><td><h3 class='nadpis3'>Estimated duration</h3><p class='hodnota'>EstTime</p></td></tr><tr><td><h3 class='nadpis3'>Environments affected</h3><p class='hodnota'>EnvAffected</p></td></tr><tr><td><h3 class='nadpis3'>Components affected</h3><p class='hodnota'>Services</p><br/></td></tr></TABLE> </CENTER></BODY></HTML>";
$result1 = $htmltext.replace('DateTime', $DateTime);
$result2 = $result1.replace('TimeZone', $TimeZone);
$result3 = $result2.replace('EstTime', $EstTime);
$result4 = $result3.replace('EnvAffected', $EnvAffected);
$result5 = $result4.replace('Services', $Services);
Get-Content -Path "C:\_DEV\addresses.txt"|ForEach-Object -Process {
$Adresa = $_;
$CharArray = $Adresa.Split(",");$mail=$CharArray['0'].Trim();
#$osloveni=$CharArray['1'].Trim();
$outlook = new-object -comobject outlook.application;
$email = $outlook.CreateItem(0);
$account = $email.Session.Accounts.Item($sender);
Invoke-SetProperty -Object $email -Property "SendUsingAccount" -Value $account;
$email.To = $mail;
$email.Subject = $Subject;
$attchmnt=$CharArray['2'].Trim();
if($attchmnt -eq "0"){
#-- do not add any file"
}else {
$email.Attachments.Add("C:\_DEV\addresses.txt");#adjust the filename and path with recipients addresses
};
$email.HTMLBody = $result5;
$email.Send();
}