-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-an-email.ps1
44 lines (32 loc) · 1.38 KB
/
send-an-email.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
# Requires 'base64-conversion.ps1'
$ScriptDirectory = Split-Path $MyInvocation.MyCommand.Path
. (Join-Path $ScriptDirectory base64-conversion.ps1)
Function Send-EMail {
Param (
[Parameter(Mandatory=$true)]
[String]$EmailTo,
[Parameter(Mandatory=$true)]
[String]$Subject,
[Parameter(Mandatory=$true)]
[String]$Body,
[Parameter(Mandatory=$true)]
[String]$EmailFrom="[email protected]",
[Parameter(mandatory=$true)]
[String]$Password
)
$SMTPServer = "smtp.example.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, $Password);
$SMTPClient.Send($SMTPMessage)
Remove-Variable -Name SMTPClient
Remove-Variable -Name Password
} #End Function Send-EMail
Send-EMail -EmailFrom "[email protected]"`
-EmailTo "[email protected]"`
-Body "Test Body"`
-Subject "Test Subject"`
-Password (Base64-Decode "SGVsbG8gV29ybGQ=") # This isn't "secure" but at least it's not plain text.
# To get the Base64 representation of your password, just go to
# http://www.opinionatedgeek.com/dotnet/tools/base64encode/