-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSMTPauth.ps1
48 lines (40 loc) · 1.89 KB
/
SMTPauth.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
<#
This script is using meant to send messages using SMTPauth to an exchange server
This script can be used for sending bulk messages, load testing, SMTP log generating, etc.
I used it as a helper script that would help me detect spammer trends based on SMTP auth message counts
last updated: 01/10/2013 Gil
#>
#Define your variables here
$smtpHost = 'mySecure.SMTPserver.com'
$userSAMname = 'gil' #This should be the SAMname of a user that has permissions to authenticate against exchange
$userPassword = 'mySuperSecurePW!!!' #User PW
$windowsDomain = 'myDomain' #Windows domain name
$sender = '[email protected]' #Send email address
$recipient = '[email protected]' #Recipient email address
$msgCount = 300 #How many messages to send out
#Some other variables
$successCount, $ErrorCount = 0 #Let's keep track of successful/error messages.
$SmtpClient = new-object system.net.mail.smtpClient
$smtpclient.Host = $smtpHost
#Authentication based on http://msdn.microsoft.com/en-us/library/59x2s2s6.aspx
$myCreds = New-Object System.Net.NetworkCredential
$myCreds.UserName = $userSAMname
$myCreds.Password = $userPassword
$myCreds.Domain = $windowsDomain
#Create SMTP object and authenticate
$myCredentialCache = New-Object System.Net.CredentialCache
$myCredentialCache.Add($SmtpClient.Host,25,"NTLM",$myCreds)
$SmtpClient.Credentials = $myCredentialCache.GetCredential($SmtpClient.Host,25,"NTLM")
#let's loop through the messages and send out based
for($i=1; $i -le $msgCount; $i++)
{
if($i%10 -eq 0)
{ sleep -Seconds 10 }
$smtpclient.Send($sender, $recipient, "Internal Message $i", "This is a test. Bulk message #$i") #Send message
if($?) #Detect successful or not
{ $successCount++ }
else
{ $ErrorCount++ }
}
Write-Host "Success: $successCount"
Write-Host "Error: $errorCount"