PoshCode Archive  Artifact [96fc39d241]

Artifact 96fc39d241bba82c22fea3d987b98918c4a11fce5ba91f0934360598871b5d64:

  • File dd-txt.ps1 — part of check-in [9f1a069536] at 2018-06-10 14:05:41 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: Richard van Erk size: 960)

# encoding: ascii
# api: powershell
# title: dd.txt
# 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
# author: Richard van Erk
# license: CC0
# x-poshcode-id: 5994
# x-archived: 2016-07-15T11:33:48
# x-published: 2016-08-28T09:18:00
#
#
$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()