Posts

Showing posts from January, 2018

Additional Information using COM object to send email from Powershell

So I found that if you happen to be in an environment were you have more than one mailbox and you have permissions to send from that other mailbox. You might think that just using the From attribute in the object would send your email from that other mailbox. Well if you thought that you would find you are mistaken (or at least I was). You have to use the "SentOnBehalfOfName" attribute to be able to make your email send from that other mailbox. Here is a handy little function to give you a hand. function Send-Email ( [string] $ Address , [string] $ CCAddress , [string] $ BCCAddress , [string] $ Subject , [string] $ HTMLBody , [string] $ FromAddress) { $ Outlook = New-Object - ComObject Outlook.Application $ Mail = $ Outlook .CreateItem ( 0 ) If(!( [string] ::IsNullOrWhiteSpace ($ FromAddress ))) { $ Mail .SentOnBehalfOfName = $ FromAddress } If (!( [string] ::IsNullOrWhiteSpace ($ CCAddress ))) { $ Mail .CC = $ CCAddress