-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Valid_emails_list.ps1
171 lines (143 loc) · 3.56 KB
/
Valid_emails_list.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Validate emails by sending commands to an SMTP server
# https://github.com/gscales/Powershell-Scripts/blob/master/TLS-SMTPMod.ps1
$check_email = test@test.com
$Array = @()
foreach ($email in $Array)
{
# Initial check
try
{
$Parameters = @{
Name = ([mailaddress]$email).Host
Type = "MX"
}
try
{
$Resolve = Resolve-DnsName @Parameters -ErrorAction Stop
}
catch
{
Add-Content -Path D:\1.txt -Value "$email. Initial check failed" -Force
continue
}
}
catch
{
Add-Content -Path D:\1.txt -Value "$email. Initial check failed" -Force
continue
}
if ($Resolve)
{
$NameExchange = (Resolve-DnsName -Name ($Resolve.Name | Select-Object -First 1) -Type MX).NameExchange | Select-Object -First 1
<#
if ($Resolve)
{
$Parameters = @{
SmtpServer = $NameExchange
Port = 25
From = $check_email
To = $email
Subject = "Test"
Body = "Test"
}
Send-MailMessage @Parameters
}
#>
$email
try
{
$Socket = New-Object -TypeName System.Net.Sockets.TcpClient($NameExchange, 25)
}
catch
{
Write-Warning -Message "$email. Connection was forcibly closed by the remote host"
Add-Content -Path D:\1.txt -Value "$email. Connection was forcibly closed by the remote host" -Force
continue
}
$stream = $Socket.GetStream()
try
{
$streamWriter = New-Object -TypeName System.IO.StreamWriter($stream)
}
catch
{
Write-Warning -Message "$email. Cannot access a disposed object"
Add-Content -Path D:\1.txt -Value "$email. Cannot access a disposed object" -Force
$stream.Close()
continue
}
$streamReader = New-Object -TypeName System.IO.StreamReader($stream)
$streamWriter.AutoFlush = $true
$ConnectResponse = $streamReader.ReadLine()
if (-not ($ConnectResponse.StartsWith("220")))
{
Write-Warning -Message $ConnectResponse
Add-Content -Path D:\1.txt -Value "$email. $ConnectResponse" -Force
$streamWriter.WriteLine("QUIT")
$stream.Close()
continue
}
else
{
Write-Verbose -Message $ConnectResponse -Verbose
}
# https://datatracker.ietf.org/doc/html/rfc1869#section-4
try
{
$streamWriter.WriteLine("HELO $check_email")
}
catch
{
Write-Warning -Message "$email. Cannot access a disposed object"
Add-Content -Path D:\1.txt -Value "$email. Cannot access a disposed object" -Force
$streamWriter.WriteLine("QUIT")
$stream.Close()
continue
}
$ehloResponse = $streamReader.ReadLine()
if (-not ($ehloResponse.StartsWith("250")))
{
Write-Warning -Message $ehloResponse
Add-Content -Path D:\1.txt -Value "$email. $ehloResponse" -Force
$streamWriter.WriteLine("QUIT")
$stream.Close()
continue
}
else
{
# Write-Verbose -Message $ehloResponse -Verbose
}
$streamWriter.WriteLine("MAIL FROM:<$check_email>")
$FromResponse = $streamReader.ReadLine()
if (-not ($FromResponse.StartsWith("250")))
{
Write-Warning -Message $FromResponse
Add-Content -Path D:\1.txt -Value "$email. $FromResponse" -Force
$streamWriter.WriteLine("QUIT")
$stream.Close()
continue
}
else
{
# Write-Verbose -Message $FromResponse -Verbose
}
# Write-Verbose -Message QUIT -Verbose
$streamWriter.WriteLine("QUIT")
$Quit = $streamReader.ReadLine()
if (-not ($Quit.StartsWith("221")))
{
Write-Warning -Message $ToResponse
Add-Content -Path D:\1.txt -Value "$email. $Quit" -Force
$streamWriter.WriteLine("QUIT")
$stream.Close()
continue
}
else
{
$streamReader.ReadLine()
}
# Write-Verbose -Message QUIT -Verbose
$streamWriter.WriteLine("QUIT")
$stream.Close()
}
}