2,187
edits
(→Variables: Added "Macros / Built-in Variables") |
m (→With Attachments: Corrections) |
||
Line 668: | Line 668: | ||
$smtp = New-Object Net.Mail.SmtpClient -arg $smtpServer | $smtp = New-Object Net.Mail.SmtpClient -arg $smtpServer | ||
$msg = New-Object Net.Mail.MailMessage | $msg = New-Object Net.Mail.MailMessage | ||
$attach = New-Object Net.Mail.Attachment($OutputFile) | $attach = New-Object Net.Mail.Attachment($OutputFile) # See note below | ||
$msg.From = $emailFrom | $msg.From = $emailFrom | ||
$msg.To.Add | $msg.To.Add($emailRcpt) | ||
$msg.Subject = $emailSubject | $msg.Subject = $emailSubject | ||
$msg.Body = $msgBody | $msg.Body = $msgBody | ||
$msg.Attachments.Add($attach) | |||
$smtp.Send($msg) | $smtp.Send($msg) | ||
$attach.Dispose() | $attach.Dispose() | ||
</source> | </source> | ||
* '''<code> $OutputFile </code>''' - Will normally need to be a full path as the script needn't be executing where your script is, assuming attachment is in same directory as script use the following... | |||
** <code>((Get-Location -PSProvider FileSystem).ProviderPath) + "\" + $OutputFile </code> | |||
== Exceptions and Error Handling == | == Exceptions and Error Handling == |