Help emailing formatted HTML - Please

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Nick Jaggers Nick Jaggers 2 years, 5 months ago.

  • Author
    Posts
  • #16344
    Profile photo of Nick Jaggers
    Nick Jaggers
    Participant

    Having problems emailing an HTML report (script attached) I can run script and outputs a nice formatted table with conditioning as an HTML page, but either missing a trick sending as an email (works without the formatting) or I am using technique that is not really compatible.
    I'm very much still learning so any help would be much appreciated.

    Thanks

  • #16347
    Profile photo of Martin Nielsen
    Martin Nielsen
    Participant

    In the html file you generate, you attach the head before outputting it to a file. When you email it you only send the body.

    You've got to

    $body = ConvertTo-Html -Head $Head -PostContent "$(get-date)" -Body $body | Out-String
    
    send-mailmessage @Smtpsettings -Body $body -BodyAsHtml
    
  • #16354
    Profile photo of Nick Jaggers
    Nick Jaggers
    Participant

    Thanks Martin, will test it tomorrow, cheers!

  • #16368
    Profile photo of Nick Jaggers
    Nick Jaggers
    Participant

    Worked a treat, many thanks!

You must be logged in to reply to this topic.