How can I send the result of a Powershell (v 2.0) script by using IP address and port number of an SMTP server (e.g xxx.xxx.xx.xxx:xx) with anonymous authentication which does not require secure connection?
1 Answer
Here is a small script, don't forget, you are on the top of the .NET framework:
Param([string[]] $to = $(throw "Please Specify a destination !"), [string] $subject = "<No Subject>", [string] $body = $(throw "Pleasr specify a content !"), [string] $smtpHost = $(throw "Please specify a SMTP server !"), [string] $from = $(throw "Please specify from email address !") ) ## Message creation $email = New-Object System.Net.Mail.MailMessage ## Fill the fields foreach($mailTo in $to) { $email.To.Add($mailTo) } $email.From = $from $email.Subject = $subject $email.Body = $body ## Send the message $client = New-Object System.Net.Mail.SmtpClient $smtpHost $client.UseDefaultCredentials = $true $client.Send($email)