header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Sending email through Exchange Server
Last Post 04 Oct 2011 01:25 PM by Karl Mitschke. 11 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BruceLUser is Offline
New Member
New Member
Posts:4
Avatar

--
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 ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    03 Oct 2011 08:33 AM
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    03 Oct 2011 09:54 AM
    Look at Send-MailMessage

    Get-Help Send-MailMessage -Examples 


    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    03 Oct 2011 10:02 AM
    Ha ha! I think I went a bit overboard...
    BruceLUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    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 MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    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 MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    03 Oct 2011 11:09 AM
    Posted By Marco Shaw (MVP) on 03 Oct 2011 11:02 AM
    Ha ha! I think I went a bit overboard...

    I was wondering if you saw a requirement that I missed ;)

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    BruceLUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    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 MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    03 Oct 2011 12:30 PM
    Try mail.scottrade.com or smtp.scottrade.com, or ask one of the Exchange administrators for the name of the SMTP server :)

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    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
    BruceLUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    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 MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    04 Oct 2011 01:25 PM
    Glad to help :)
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer