PoshCode Archive  Artifact [01655dfc0d]

Artifact 01655dfc0df0eb54c53a4770ceb93efe89f054bdeb88dca088bfab0dc3b3e824:

  • File All-descriptions-on-the-web-.ps1 — part of check-in [f84f7e0f87] at 2018-06-10 13:49:48 on branch trunk — All descriptions on the web which show how to do this so far have left the email attachment open which means if the script is continuing after the email and you wish to use the file you have attached you will not be able to as it will show as locked, use this example to close the attached file correctly using .Dispose() (user: unknown size: 891)

# encoding: ascii
# api: powershell
# title: 
# description: All descriptions on the web which show how to do this so far have left the email attachment open which means if the script is continuing after the email and you wish to use the file you have attached you will not be able to as it will show as locked, use this example to close the attached file correctly using .Dispose()
# version: 0.1
# license: CC0
# x-poshcode-id: 5078
# x-archived: 2014-04-16T05:12:33
#
#
$file = "MYFILE.TXT"

$smtpServer = "MYSMTPSERVER.EMAIL.CO.UK"

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = "FROMME@EMAIL.CO.UK"
$msg.To.Add("TOME@EMAIL.CO.UK")
$msg.Subject = "MY SUBJECT"
$msg.Body = "MY TEXT FOR THE EMAIL"
$msg.Attachments.Add($att)

$smtp.Send($msg)

$att.Dispose()