2,187
edits
(→Comparison: Added -match and -like) |
(→SMTP / Email Sending: Added "With Attachments") |
||
Line 635: | Line 635: | ||
== SMTP / Email Sending == | == SMTP / Email Sending == | ||
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx# | http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx# | ||
Emails can be send very simply if no attachment is needed.... | |||
<source lang="powershell"> | <source lang="powershell"> | ||
$smtp = New-Object Net.Mail.SmtpClient -arg $smtpServer | $smtp = New-Object Net.Mail.SmtpClient -arg $smtpServer | ||
$smtp.Send($emailFrom,$emailRcpt,$emailSubject,$msgBody) | $smtp.Send($emailFrom,$emailRcpt,$emailSubject,$msgBody) | ||
</source> | </source> | ||
=== With Attachments === | |||
<source lang="powershell"> | |||
$smtp = New-Object Net.Mail.SmtpClient -arg $smtpServer | |||
$msg = New-Object Net.Mail.MailMessage | |||
$attach = New-Object Net.Mail.Attachment($OutputFile) | |||
$msg.From = $emailFrom | |||
$msg.To.Add = $emailRcpt | |||
$msg.Subject = $emailSubject | |||
$msg.Body = $msgBody" | |||
$smtp.Send($msg) | |||
$attach.Dispose() | |||
</source> | |||
== Exceptions and Error Handling == | == Exceptions and Error Handling == |