I have already asking the help for the Powershell to send the mail through SMTP with the excel content.Now i have made .html which creates a Table where the data needs to be copied inside the table.When i copy the html code which through the error for &,since the body is in HTML format which is not accepting.Any suggestions.Whether the html code path can be given if yes how to proceed.HTML code is 2000 lines where gives the proper output of the table
$email = "[email protected]"
$smtpServer = "mail.somecompany.com"
$ForEmail = @()
######################################
#Create and get my Excel Obj
$x1 = New-Object -comobject Excel.Application
$UserWorkBook = $x1.Workbooks.Open("C:\temp\bluenose.xlsx")
#Select first Sheet
$UserWorksheet = $UserWorkBook.Worksheets.Item(1)
$UserWorksheet.activate()
#Copy the part of the sheet I want in the Email
$rgeSource=$UserWorksheet.range("A1","E20")
$rgeSource.Copy() | out-null
$Results = Get-Clipboard
foreach ($Result in $Results)
{
$ForEmail += "$Result<br>"
}
######################################
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "[email protected]"
$msg.To.Add($email)
$msg.Subject = "Excel Pasted"
$msg.IsBodyHtml = $True
$msg.Body = "Here is the contents of the excel file<br>
<br>
$ForEmail
<br>
"
$smtp.Send($msg)