O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.1. Using System.Net.Mail

System.Net.Mail is a namespace in the .NET 2.0 Framework that provides classes dealing with all the intricacies involved with sending e-mail. Those classes know how to create a mail message, how to encode it and its attachments, and how to talk the server into sending it to the correct recipients. The basic mail sending functionality is quite simple to achieve: we create a MailMessage object; set it up with the correct recipient address, subject, and body; and pass it to an SmtpClient that actually sends the message over the wire. The following sample script, send-plain.ps1, does exactly that:

#create the mail message $mail = New-Object System.Net.Mail.MailMessage #set the addresses $mail.From = New-Object System.Net.Mail.MailAddress("test@deshev.com") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required