powershell脚本将html文件附加到电子邮件正文

时间:2016-04-18 10:27:37

标签: html powershell

Iam正在寻找一个Powershell脚本来将html文件附加到电子邮件正文中。请通过提供示例脚本来帮助我。我当前的脚本无法正常工作。我无法在电子邮件正文中获取html文件内容每次都会更改.html文件的名称。

1 个答案:

答案 0 :(得分:0)

我使用了2个脚本,但我想你可以使用一个 制作html文件

            $FILENAME = HTMLfilename
            $head = @'
            <title>page title</title>
            <style> maybe some css</style>
            '@
            $title01 = @'
            <h1>some text above html file</h1>
            '@
            $body = @"
            <a href='$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"

发送电子邮件

            $Credential = New-Object System.Management.Automation.PsCredential($EmailUsername, $Emailpassword)
            $EmailFrom = "from@domain.com" 
            $EmailTo = @("<to@domain.com>")
            #$EmailCc = @("<EMAIL>")
            $EmailSubject = "email  subject"
            $EmailBody = "a link to html file" 
            #OR maybe Attach it
            #$EmailAttachments = "PATH\TO\HTML\FILE\$FILENAME.html" 
            $SMTPServer = "smtp.@domain.com"
            $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