我知道如何使用 cat 文件
cat file.txt
但我有变量
[string]$body = "Body message here"
我需要帮助更改它以从中获取文本内容file.txt
我试过了,但没有用。
[string]$body = $cat file.txt
这是完整的脚本,我正在尝试更改param
部分。
param
(
[string]$email = $(read-host "Enter a recipient email"),
[string]$subject = $(read-host "Enter the subject header"),
[string]$body = $(read-host "Enter the email text (optional)")
)
到
param
(
[string]$email = "my@email.com",
[string]$subject = "server",
[string]$body = gc C:\Users\myuser\Documents\somefolder\GnuWin32\bin\status.txt
)
# ==========================================================================
# Functions
# ==========================================================================
function Send-Email
(
[string]$recipientEmail = $(Throw "At least one recipient email is required!"),
[string]$subject = $(Throw "An email subject header is required!"),
[string]$body
)
{
$outlook = New-Object -comObject Outlook.Application
$mail = $outlook.CreateItem(0)
$mail.Recipients.Add($recipientEmail)
$mail.Subject = $subject
$mail.Body = $body
# For HTML encoded emails
# $mail.HTMLBody = "<HTML><HEAD>Text<B>BOLD</B> <span style='color:#E36C0A'>Color Text</span></HEAD></HTML>"
# To send an attachment
# $mail.Attachments.Add("C:\Temp\Test.txt")
$mail.Send()
Write-Host "Email sent!"
}
Write-Host "Starting Send-MailViaOutlook Script."
# Send email using Outlook
Send-Email -recipientEmail $email -subject $subject -body $body
Write-Host "Closing Send-MailViaOutlook Script."