I want to send out emails using Powershell and outlook but the sender email needs to be different. Currently this is what i have:
$OL = New-Object -comObject Outlook.Application
$mItem = $OL.CreateItem("olMailItem")
$mItem.SentOnBehalfOfName = "newEmail@email.com"
$mItem.To = "rec@email.com"
$mItem.Subject = "test"
$mItem.HTMLBody = "test"
$mItem.send()
My IT admin gave me an additional outlook email address. So i added the line for SentOnBehalfOfName but i get the error mail: "This message could not be sent. You do not have the permission to send the message on behalf of the specified user. "
Does anyone know what permissions are needed? I had an idea for a solution but I don't if it would work. My outlook has my default profile address. name@email.com and its the primary one somewhere in the system so when i make an outlook email through powershell , it uses it. Is there a way to switch to the new one i was given? If the new one is a shared email even though i am the only one it, will it still work?
Thank you
EDIT: Note that doing it directly from outlook by changing the From option does work for me. So now i just need to do it by powershell. I also tried setting the $mItem.Sender but i get the same error.