My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#----------------------------------------------------------------------------------------
#
# A Mailer script that makes use of System.Net to send email with attachments
#
# Sample usage:
#
# PS> Send-Mail-With-Attachment 'your-email-address@domain.com' 'Hello world!' 'Filename.txt'
#
#----------------------------------------------------------------------------------------

function global:Send-Mail-With-Attachment([string] $to, [string] $subject, [string] $file){
$filenameAndPath = (Resolve-Path .\$file).ToString()
$from = 'Automated Powershell Mailer'

[void][Reflection.Assembly]::LoadWithPartialName('System.Net') | out-null

$message = New-Object System.Net.Mail.MailMessage($from, $to, $subject, $subject)
$attachment = New-Object System.Net.Mail.Attachment($filenameAndPath, 'text/plain')
$message.Attachments.Add($attachment)

$smtpClient = New-Object System.Net.Mail.SmtpClient
$smtpClient.host = 'mail.domain.com'
$smtpClient.Send($message)
}

Change log

r58 by kahtava on Jan 16, 2010   Diff
Added a PowerShell Mailer script that
sends email with attachments using the
System.Net object.
Go to: 
Sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1004 bytes, 24 lines
Powered by Google Project Hosting