BruceL
 New Member Posts:4

 |
| 03 Oct 2011 07:58 AM |
|
I'm still a bit new to PowerShell and this may be so easy that this is why I can't find examples. If the script I have fails to complete successfully I want an email sent to our group alerting that it failed. The script runs on a Windows Server 2003. We use Exchange Server 2007. Is there an example of some code and cmdlets that will do the job? I just want to send an email, but what I've seen in the forums has more to do with Exchange Server management. I did see one example using Outlook, but this is a server and Outlook was never setup.
Thanks very much! |
|
|
|
|
Marco Shaw
 Veteran Member Posts:1684

 |
|
Karl Mitschke
 Basic Member Posts:457

 |
|
Marco Shaw
 Veteran Member Posts:1684

 |
| 03 Oct 2011 10:02 AM |
|
Ha ha! I think I went a bit overboard... |
|
|
|
|
BruceL
 New Member Posts:4

 |
| 03 Oct 2011 10:09 AM |
|
I tried Send-MailMessage, but couldn't figure out how to get it to work with Exchange Server. |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
| 03 Oct 2011 11:08 AM |
|
You just need to know the name of your smtp server
Send-MailMessage -To karlmitschkecontoso.com -from karlmitschke@hotmail.com -Subject "Test Email" -SmtpServer mail.domain.com
Try your exchange server fqdn for mail.domain.com Karl |
|
http://unlockpowershell.wordpress.com
Co-Author, Windows PowerShell 2.0 Bible
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"}) |
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
BruceL
 New Member Posts:4

 |
| 03 Oct 2011 11:27 AM |
|
Karl, when I try your suggestion (using my exchange server and email address after -To, I get the following error: Send-MailMessage : Unable to connect to the remote server At C:\Scripts\SendMailMessage-simple.ps1:1 char:17 + Send-MailMessage <<<< -To blundquist@scottrade.com -From blundquist@scottrade.com -Subject "Hello!" -Body "This is a test" -SmtpServer XXXXXXX.scottrade.com + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept ion + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage I know the name of the exchange server. So why does it say it's unable to connect? |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
Marco Shaw
 Veteran Member Posts:1684

 |
| 03 Oct 2011 01:11 PM |
|
Make sure you have a connector that works with SMTP TCP/25 before trying to use PowerShell. If you're not sure, and you aren't the Exchange administrator, try the steps outlined here: http://support.microsoft.com/kb/153119 |
|
|
|
|
BruceL
 New Member Posts:4

 |
| 04 Oct 2011 01:05 PM |
|
I've got it to work. I contacted the messaging admin, got the correct name of the smtp server and put it altogether in Send-MailMessage. It was successful. This is a huge blow for freedom! Thank you guys very much. |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|