SendUsingAccount is not working in Powershell

(Yes, I know both Send-MailMessage and Net.Mail.SmtpClient exist)



$Outlook = New-Object -ComObject Outlook.Application
foreach ($account in $Outlook.Application.Session.Accounts)
if ($account.UserName -eq “accountusername”)
$Mail = $Outlook.CreateItem(0)
$Mail.To = “
$Mail.Subject = “a subject”
$Mail.HTMLBody = “i am message<br /><br />”

Im trying to send email from another Exchange account on my Outlook but it is not working. It sends it from the default.

Below solution might work for you.