Sending E-mail With PowerShell

Been looking for something like this in a while to test newly setup or existing SMTP setups for simple server notification or business applications e.g. SharePoint, as it saves you having to install telnet or putty in order to send a quick test email to make sure its not getting blocked somewhere i.e. spam:

## Update ##
Just found out there’s an actual powershell Cmdlet for this: Send-MailMessage!


$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

#Email structure
$msg.From = "fromID@xxxx.com"
$msg.To.Add("toID@xxxx.com")
$msg.subject = "My Subject"
$msg.body = "This is the email Body."

#Sending email
$smtp.Send($msg)

Thanks to SharePoint and Others for the basics!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s