SMTPClient - Mail with .txt file in body message
suggest change# Define the txt which will be in the email body
$Txt_File = "c:\file.txt"
function Send_mail {
#Define Email settings
$EmailFrom = "source@domain.com"
$EmailTo = "destination@domain.com"
# -Raw is Windows PowerShell 3.0 and later. It returns one string.
$Txt_Body = Get-Content $Txt_File -Raw
$Body = $Body_Custom + $Txt_Body
$Subject = "Email Subject"
$SMTPServer = "smtpserver.domain.com"
# SmtpClient is obsolete in current .NET, but this is the API the sample uses.
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 25)
$SMTPClient.EnableSsl = $false
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
$Body_Custom = "This is what file.txt contains: "
Send_mail
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents