[Solved] powershell script to attach the html file in body of email


i used 2 scripts but i suppose you could use one
Make the html file

            $FILENAME = HTMLfilename
            $head = @'
            <title>page title</title>
            <style> maybe some css</style>
            '@
            $title01 = @'
            <h1>some text above html file</h1>
            '@
            $body = @"
            <a href="https://stackoverflow.com/questions/36691354/$FILENAME.html">filename</a> 
            '@
            $x = some code
            $x | Select-object Name | ConvertTo-HTML -head $head -PreContent $title01 -PostContent "some text" -body $body | Out-File "PATH\TO\HTML\FILE\$FILENAME.html"

Send the email

            $Credential = New-Object System.Management.Automation.PsCredential($EmailUsername, $Emailpassword)
            $EmailFrom = "[email protected]" 
            $EmailTo = @("<[email protected]>")
            #$EmailCc = @("<EMAIL>")
            $EmailSubject = "email  subject"
            $EmailBody = "a link to html file" 
            #OR maybe Attach it
            #$EmailAttachments = "PATH\TO\HTML\FILE\$FILENAME.html" 
            $SMTPServer = "[email protected]"
            $SMTPPort = ####
            $SMTPSsl = $True 
            $param = @{ 

            SmtpServer = $SMTPServer 
            Port = $SMTPPort 
            UseSsl = $SMTPSsl   
            Credential = $Credential    
            From = $EmailFrom   
            To = $EmailTo
            #Cc = $EmailCc  
            Subject = $EmailSubject 
            Body = $EmailBody 
            #Attachments = $EmailAttachments    
            } 


            Send-MailMessage @param

1

solved powershell script to attach the html file in body of email