Sending Mail using Power Shell and a Configured Outlook Exchange Account

I've been looking for a way to send mail through an Exchange account on a normal Windows workstation from the command line, using powershell 2.0

I've found several ways to do it, using a SMTP server, but is there a way to use an existing Outlook Exchange account that is already configured on the workstation?

An example would be great.

Thanks.
madorianAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Scott CSenior EngineerCommented:
footechCommented:
The Send-MailMessage cmdlet is available since PS 2.0 (some additional capabilities were added to it in PS 3.0).  This works fine for sending messages via SMTP server.  Depending on your Exchange server configuration, you can usually submit messages to it with no problem.

But if you want to actually send the messages with Outlook, you have to access it via COM object.
$o = New-Object -ComObject Outlook.Application
$mail = $o.CreateItem(0)
$mail.subject = "Test subject"
$mail.body = "Here's the body text."

#for multiple email, use semi-colon ; to separate
$mail.To = "someone@theirdomain.com"
# appears it's also possible to use the below
#$mail.Recipients.Add("otherperson@theirdomain.com") 
$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
madorianAuthor Commented:
Thank you. This seems to be the answer. I've found some more info thanks to this and I'll try to figure out how it's using a specific profile. I'll get back to you if I'm stuck. Thanks.
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
Outlook

From novice to tech pro — start learning today.