Replacing Powershell send-mailmessage with Graph

Copper Contributor
I'm pretty new to graph and we are trying to update one of our scripts that use powershell so we can use the newest version of powershell with the Graph SDK (Microsoft is deprecating the send-mailmessage command) . Below we are creating a variable $outputHTML and formatting the body of an email we want to send. We then use the old powershell command which grabs the $outputHTML and sends it in an email.  [Send-MailMessage -To $Toadd -Subject "New Mailbox $Disp $DateStamp" -From email address removed for privacy reasons  -Body ($outputhtml | Out-String) -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8) -SmtpServer XXXXXX]. 
Below is a snippet of the script. 
Any idea how I can use graph to send this same email with the same content preserving the same format that is created in the $outputHTML variable? 
 
Any assistance would be appreciate. Thanks!
 
 
      $outputHtml = @"
      <style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #C0C0C0;}
td.pass{background: #7FFF00;}
                td.memb{background: #00AAFF;}
td.warn{background: #FFE600;}
td.fail{background: #FF0000; color: #ffffff;}
td.info{background: #85D4FF;}
                td.gray{background: #E1E1EA;}
td.silv{background: #C0C0C0;}
                td.cora{background: #ffcc66;}
</style>
<H2>$disp</H2>
<H3>$acctmember</H3>
 
<table>
<tr><td>Last Name</td><td class="gray">$last</td></tr>
<tr><td>First Name</td><td class="gray">$first</td></tr>
<tr><td>Middle Initial</td><td class="gray">$Init</td></tr>
<tr><td>Office</td><td class="gray">$Office</td></tr>
<tr><td>Country/Region</td><td class="gray">$UsageLocation</td></tr>
<tr><td>PDL</td><td class="gray">$PDL</td></tr>
<tr><td>Title</td><td class="gray">$Title</td></tr>
<tr><td>Department</td><td class="gray">$Dept</td></tr>
<tr><td>Primary SMTP Address</td><td class="gray">$psmtpa</td></tr>
<tr><td>User Principal Name</td><td class="gray">$script:upn</td></tr>
<tr><td>Email Addresses</td><td class="gray">$EmailAdds</td></tr>
<tr><td>Database</td><td class="gray">$database</td></tr>
<tr><td>EXO Retention Policy</td><td class="gray">$retpolicy</td></tr>
<tr><td>OU</td><td class="gray">$OU</td></tr>
<tr><td>UPN</td><td class="gray">$UPN</td></tr>
<tr><td>Retain Deleted Items</td><td class="gray">$retaindeleted</td></tr>
<tr><td>OWA Policy</td><td class="gray">$OWApolicy</td></tr>
<tr><td>Single Item Recovery</td><td class="gray">$sirp</td></tr>
<tr><td>Send on Behalf of Item Copy</td><td class="gray">$sendonbehalf</td></tr>
<tr><td>Send As Item Copy</td><td class="gray">$SendAsItemsCopiedTo</td></tr>
<tr><td>Is Reply All Default</td><td class="gray">$ReplyAllDefault</td></tr>
<tr><td>Role Assignment Policy</td><td class="gray">$RoleAP</td></tr>
<tr><td>Max Message Send Size</td><td class="gray">$SendSize</td></tr>
<tr><td>Max Message Receive Size</td><td class="gray">$RecSize</td></tr>
</table>
 
 
"@;
    $OutFilehtml = "d:\scripts\NewMailbox_" + $Username + "_" + $DateStamp + ".html"
    $outputhtml | Out-File $outfilehtml
    $ToAdd = @("email address removed for privacy reasons", "email address removed for privacy reasons")
 
Send-MailMessage -To $Toadd -Subject "New Mailbox $Disp $DateStamp" -From email address removed for privacy reasons  -Body ($outputhtml | Out-String) -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8) -SmtpServer USPDCMAIL614P 
}
 
 
 
Gen-Ereport
####}
 
### END OF SCRIPT ####
2 Replies
Tony did a detailed exploration on this subject a while back, go over his articles if you haven't done so already. Here's a link: https://practical365.com/send-email-powershell-graph/