none
Send HTML Email with PowerShell RRS feed

  • Question

  • Hi,

    I am trying to send a report using send-mailmessage cmdlet and I am unable to send it.

    Script:

    $fromaddress = "x.y@xy.com"
    $toaddress = "x.y@xy.com"
    $CCaddress = "x.y@xy.com"
    $Subject = "Test Change Management"
    $body = Get-Content -Path C:\Users\V004701\Documents\PowerShell\test.txt -Raw
    $smtpserver = "Ddc.vt.ch"
     
    ####################################
     
    $message = new-object System.Net.Mail.MailMessage
    $message.From = $fromaddress
    $message.To.Add($toaddress)
    $message.CC.Add($CCaddress)
    $message.Subject = $Subject
    $message.body = $body
    $smtp = new-object Net.Mail.SmtpClient($smtpserver)
    $smtp.Send($message)

    Error Message: Exception calling "Send" with "1" argument(s): "Failure sending mail."
    At line:19 char:1
    + $smtp.Send($message)
    + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : SmtpException
     

    Thanks for ur Help :)

    User V004701

    Thursday, November 7, 2019 9:47 AM

All replies

  • Don't use that old and mostly never used code. Use this:

    help send-mailmessage -online


    \_(ツ)_/

    Thursday, November 7, 2019 10:13 AM