Sending Simple SMTP Mail

by Mar 31, 2009

You need to notify an admin that something happened or something is finished and would like to send a quick e-mail from inside your PowerShell scripts. Here is a simple wrapper allowing you to use any standard SMTP server to send simple e-mails:

function Send-mySMTP {
param($server, $recipient, $username, $password, $sender, $title, $body)
$SmtpClient = new-object system.net.mail.smtpClient
$smtpclient.Host = $server
$Credentials = new-object System.Net.networkCredential

$Credentials.domain = ""
$Credentials.UserName = $username
$Credentials.Password = $password
$SMTPClient.Credentials = $Credentials
$smtpclient.Send($sender, $recipient, $title, $body)
}