-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListing 7.2.ps1
57 lines (56 loc) · 1.11 KB
/
Listing 7.2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function Send-Email
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
$From,
[Parameter(Mandatory = $true)]
[array]$To,
[array]$bcc,
[array]$cc,
$body,
$subject,
$attachment,
[Parameter(Mandatory = $true)]
$smtpserver
)
$message = New-Object System.Net.Mail.MailMessage
$message.From = $From
if ($To -ne $null)
{
$To | ForEach-Object{
$to1 = $_
$to1
$message.To.Add($to1)
}
}
if ($cc -ne $null)
{
$cc | ForEach-Object{
$cc1 = $_
$cc1
$message.CC.Add($cc1)
}
}
if ($bcc -ne $null)
{
$bcc | ForEach-Object{
$bcc1 = $_
$bcc1
$message.bcc.Add($bcc1)
}
}
$message.IsBodyHtml = $true
if ($subject -ne $null)
{$message.Subject = $subject}
if ($attachment -ne $null)
{
$attach = New-Object Net.Mail.Attachment($attachment)
$message.Attachments.Add($attach)
}
if ($body -ne $null)
{$message.body = $body}
$smtp = New-Object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)
} # Send-Email