如果文本包含多個句子,則向文本添加文本不會正確添加任何語句。來自文件的正文文本
Content @爲空。
它只添加一個簽名。
輸入文件(名稱:Text_file.txt
):
email:[email protected] emialcc: emailbcc: Subject:2513000013 attachment:Y:\attachment\2513000013.pdf
文本文件:
This is a test This and other lines do not show up test3 test4 test5
PowerShell腳本:
$destDir = "C:\M3_Outlook"
if (!(Test-Path $destDir)) {
New-Item -Path $destDir -ItemType Directory
} else {}
$file_patch = Get-ChildItem 'C:\M3_Outlook' | Sort {$_.LastWriteTime} |
select -Last 1 | % { $_.FullName }
$name = Select-String -Path $file_patch -pattern name
$email = Select-String -Path $file_patch -pattern email
$subject=Select-String -Path $file_patch -pattern subject
$attachment = Select-String -Path $file_patch -pattern attachment
$Signature = Get-Content ($env:USERPROFILE + "\AppData\Roaming\Microsoft\Signatures\*.htm")
$rname = $name -replace ".*:"
$remail = $email -replace ".*:"
$rsubject = $subject -replace ".*:"
$rattachment = $attachment -replace ".*attachment:"
$rattachment
$sname = $rname -split ";"
$semail = $remail -split ";"
$ssubject = $rsubject -split ";"
$sattachment = $rattachment -split ";"
$body = Get-Content C:\M3_Outlook\PPS200.txt
$Signature = Get-Content ($env:USERPROFILE + "\AppData\Roaming\Microsoft\Signatures\*.htm")
$sRecipientAddr = $semail
$sMsgSubject = $ssubject
$oOutlook = New-Object -ComObject Outlook.Application
$oMapiNs = $oOutlook.GetNameSpace("MAPI")
$oMailMsg = $oOutlook.CreateItem(0)
$oMailMsg.GetInspector.Activate()
$sSignature = $oMailMsg.HTMLBody
$sSignature = $oMailMsg.HTMLBody
$sattachment | ForEach-Object { $oMailMsg.Attachments.Add($_) }
$oMailMsg.TO = $semail
$oMailMsg.Subject = $sMsgSubject
$oMailMsg.HTMLBody = $body + $sSignature
任何人都知道,這可能是對這種行爲的原因以及如何解決它?
我不清楚你面臨什麼問題。你的代碼中哪部分不起作用,以及它究竟如何「不起作用」,即什麼是期望的和實際的結果? –