Powershell to Send Email Message

I'm trying to write a poweshell script that sends an outbound email.  I've gotten the script to work perfectly the problem is we have a third part application that embedds a logo in all outgoing messages in the message.  Sending a message through Outlook works flawlesssly but for whatever reason when using the script for whatever reason the message isn't being sent as an HTML message so the logo is sen as an attachment to a gmail address for example.  I essentialy trying to send a test message from every user in our environment to test outgoing signatures that are applied by this same 3rd part application..  
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -BodyAsHtml -SmtpServer $SMTPServer -port $SMTPPort -Priority High

Open in new window

georgedschneiderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
I don't think the problem is with your command, as that will send an HTML message.
I'd suspect it's more something to do with the third-party app.

What happens when you send a plain-text email using Outlook?  Do you get the same result as what you're seeing when sending from PS?

Does $body actually contain HTML code?
georgedschneiderAuthor Commented:
$body does not contain HTML code.  $body = Test Email.  The problem with sending a plain text email is the signature program does not add the logo when the email is sent through plain text.  I thought about writing a script to send a message through outlook but the problem is I can figure out how to use send as to send as a another user who I have the rights to send as.  The code i was using is as follows:

$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$Mail.Recipients.Add("user@gmail.com")  
$Mail.Subject = "Testing"  
$Mail.Body = "This is my test email"  
$Mail.Send() 

Open in new window

footechCommented:
The reason I asked about sending a plain-text email with Outlook is because I'm trying to figure out if your third-party app embeds the logo by looking at specific HTML code in the email.  If you see the same behavior with Outlook sending plain-text, then it would seem to indicate that adjusting your code so that $body contains HTML code would resolve the issue.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

georgedschneiderAuthor Commented:
If  $body = "This is a test".  How can I adjust the code so it contains HTML code.
Michael MachieIT SupervisorCommented:
I do not see the ConvertTo-HTML command in your script, nor the style to use as HTML.

Please reference these links:
http://exchangeserverpro.com/powershell-send-html-email/
http://exchangeserverpro.com/powershell-html-email-formatting/
georgedschneiderAuthor Commented:
I was able to accomplish the task using the below code but I don't exactly understand how its worksing since the account I'm running as has neither send as or send on behalf rights but has full mailbox to all mailboxes as well a member of org. management.

$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$Mail.SentOnBehalfOfName = "send@domain.com"
$Mail.Recipients.Add("recipient@gmail.com")  
$Mail.Subject = "Testing"  
$Mail.Body = "This is my test"  
$Mail.Send() 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
"Full mailbox access" includes "Send on Behalf".
The Outlook approach works probably because it forces mail to be HTML. You need to do the same, by sending HTML code:
Send-MailMessage -From $From -to $To -Subject $Subject -Body ($Body | convertTo-HTML) BodyAsHtml -SmtpServer $SMTPServer -port $SMTPPort -Priority High

Open in new window

is the absolute minimum you need to do. You might have issues with forced line breaks, but since you only want to send a test mail, this should work.
georgedschneiderAuthor Commented:
Using Outlook to send the messages forced the email message to go via HTML
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.