Lately I’ve been setting up a back-end script for one of our customers.
The full script creates Domain users and adds them to domain groups, generates passwords and emails the manager/CEO the user information.

This post will only contain the Email function, more functions will be posted later.

Function SendMail{
     #SMTP server name
     $SMTPServer = "SMTP.telia.se" #Change this: Your SMTP server

     #Creating a Mail object
     $Msg = new-object Net.Mail.MailMessage

     #Creating SMTP server object
     $SMTP = new-object Net.Mail.SMTPClient($SMTPServer)

     #Email structure 
     $Msg.From = "[email protected]"
     $Msg.ReplyTo = "[email protected]"
     $Msg.To.Add("[email protected]")
     $Msg.subject = "Powershell is king!"
     $Msg.body = "Hi," + "`r`n" + `
                 "I'm a heineborn.com visitor!"

     #Sending email 
     $SMTP.Send($Msg)
}

Now please don’t use this to spam people, it’s a bad idea! :)

Let me know if you need help, and please share this post!