locked
Adding CC to System.Net.Mail.MailMessage email alert RRS feed

  • Question

  • Hello,

    I'm having difficulties adding a CC email address to this Exchange 2007 powershell script I found online.

    I have tried the obvious

    e.g.

    $ToAddress = "Support@Domain.com","support2@Domain.com

    and

    $emailMessage.To.Add( "jane@somewhere.com" )
    $emailMessage.To.Add( "jim@somewhere.com" )

    But nothing works for me..

    Please advise

    ....

    $FromAddress = "srv01@Domain.com"
    
    $ToAddress = "Support@Domain.com"
    
    
    $MessageSubject = "Queue Alert"
    $MessageBody = $Body
    $SendingServer = "smtp.smtpserver.co.uk"
    $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
    $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
    $SMTPClient.Send($SMTPMessage)
     }
    

    Monday, September 12, 2016 11:36 AM

Answers

  • Hi,

    well, your message object has a "cc" property, which can be used:

    $FromAddress = "srv01@Domain.com"
    $ToAddress = "Support@Domain.com"
    $CcAddress = "cc@Domain.com"
    
    
    $MessageSubject = "Queue Alert"
    $MessageBody = $Body
    $SendingServer = "smtp.smtpserver.co.uk"
    $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
    $SMTPMessage.cc.Add($CcAddress)
    $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
    $SMTPClient.Send($SMTPMessage)

    Cheers,
    Fred

    Note: It also has a Bcc Property, in case you ever need it


    There's no place like 127.0.0.1



    • Edited by FWN Monday, September 12, 2016 12:31 PM
    • Proposed as answer by Mike Laughlin Monday, September 12, 2016 12:44 PM
    • Marked as answer by uklogistics Monday, September 12, 2016 12:45 PM
    Monday, September 12, 2016 12:29 PM

All replies

  • Hi,

    well, your message object has a "cc" property, which can be used:

    $FromAddress = "srv01@Domain.com"
    $ToAddress = "Support@Domain.com"
    $CcAddress = "cc@Domain.com"
    
    
    $MessageSubject = "Queue Alert"
    $MessageBody = $Body
    $SendingServer = "smtp.smtpserver.co.uk"
    $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
    $SMTPMessage.cc.Add($CcAddress)
    $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
    $SMTPClient.Send($SMTPMessage)

    Cheers,
    Fred

    Note: It also has a Bcc Property, in case you ever need it


    There's no place like 127.0.0.1



    • Edited by FWN Monday, September 12, 2016 12:31 PM
    • Proposed as answer by Mike Laughlin Monday, September 12, 2016 12:44 PM
    • Marked as answer by uklogistics Monday, September 12, 2016 12:45 PM
    Monday, September 12, 2016 12:29 PM
  • Just use Send-MailMessage.

    http://ss64.com/ps/send-mailmessage.html


    Monday, September 12, 2016 12:44 PM
  • Thanks Fred, that did the trick!

    $CcAddress = cc@Domain.com

    $SMTPMessage.cc.Add($CcAddress)

    Monday, September 12, 2016 12:46 PM