我正在尝试格式化接收电子邮件的措辞,使其仅包含href的URL以及网站链接的标题。我现在有脚本用href提取innerText
是否可以设置电子邮件内容中的href格式,使其更易读?
<#Gets news based on 24 hour search criteria from Google#>
$url ="https://www.google.com/search?q=this+is+a+test&sxsrf=ACYBGNQBx5fMzfpxKm96-8tVbjo2vUn3SA:1573134980847&source=lnt&tbs=qdr:d&sa=X&ved=0ahUKEwin4t29oNjlAhXDc98KHfFwAVcQpwUIKQ&biw=1366&bih=625"
$date = get-date -Uformat "%m-%d"
$response = Invoke-WebRequest -URI $url
$file = "F:\rryu\exportfile"+$date+".csv"
<#Gets title and href where href url has "/url?1=https://..." and exports it to network drive.#>
$response.Links |select-object innerText, href | where-Object {$_.href -like "/url?q=https://*"} | export-csv -path $file -NoTypeInformation
<#Makes the csv file to a string#>
$stringout = Get-Content $file | Out-String
<#Options to send out email out#>
$options = @{
'SmtpServer' = "mailrelay.xxxxxxxxxx.com"
'To' = "xxx <xxx.xxx@xxxxxxxxxx.com>"
'From' = "NoReply <donotreply@xxxxxxxxcx.com>"
'Subject' = "Testing Recent News"
'Body' = "Please review news as of "+$date + $stringout
'Attachments' = $file
}
Send-MailMessage @options
预期结果:
这是一个测试... https://www.tested.com/this-is-only-a-test/
实际结果:
“这仅是测试-已测试 https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.tested.com&data=02%7C01%7Cxxx.xxxx%40xxxxxxxxx.com%7Cdcd591d873414f6793ea08d7638b6df9%7C50488be8ac744dcd9bdd44db35d92d8d%7C1%7C0%7C637087322814017205&sdata=DAGocTHvYwPcLGIz%2FDOsE7qaoD2lRNrI7nBYaJ3EHK0%3D&reserved=0?这是一个测试“,” / url?q = https://www.tested.com/this-is-only-a-test/&sa=U&ved=2ahUKEwigs72motjlAhVpFjQIHRStBTcQFjAAegQIBRAB&usg=AOvVaw1JTUKGetVOagK6UxYKtidf“