-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcheck-connection.ps1
More file actions
54 lines (48 loc) · 2.13 KB
/
Copy pathcheck-connection.ps1
File metadata and controls
54 lines (48 loc) · 2.13 KB
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
# ====================================================================
# check-connection.ps1
# ====================================================================
# Connectivity-only healthcheck for mx.msgwing.com.
# No credentials required, no email sent. Run this first if a send is
# hanging or timing out - see docs/TROUBLESHOOTING.md for context.
# ====================================================================
$SmtpHost = "mx.msgwing.com"
$Ports = 587, 465
Write-Host "== DNS resolution =="
try {
Resolve-DnsName -Name $SmtpHost -ErrorAction Stop | Format-Table -AutoSize
}
catch {
Write-Host "Could not resolve $SmtpHost : $($_.Exception.Message)"
}
foreach ($Port in $Ports) {
Write-Host "`n== TCP connect to ${SmtpHost}:${Port} =="
$result = Test-NetConnection -ComputerName $SmtpHost -Port $Port -WarningAction SilentlyContinue
if (-not $result.TcpTestSucceeded) {
Write-Host "TCP connect: FAILED (likely blocked by your network/provider - see docs/TROUBLESHOOTING.md)"
continue
}
Write-Host "TCP connect: OK"
if ($Port -eq 465) {
Write-Host "== TLS handshake on ${SmtpHost}:${Port} (implicit TLS) =="
$tcpClient = $null
$sslStream = $null
try {
$tcpClient = New-Object System.Net.Sockets.TcpClient($SmtpHost, $Port)
$sslStream = New-Object System.Net.Security.SslStream($tcpClient.GetStream(), $false)
$sslStream.AuthenticateAsClient($SmtpHost)
Write-Host "TLS handshake: OK (protocol: $($sslStream.SslProtocol))"
}
catch {
Write-Host "TLS handshake: FAILED - $($_.Exception.Message)"
}
finally {
if ($sslStream) { $sslStream.Close() }
if ($tcpClient) { $tcpClient.Close() }
}
}
else {
Write-Host "Skipping direct TLS handshake on $Port - it requires a STARTTLS negotiation first, and TCP connectivity is already confirmed above"
}
}
Write-Host "`nNo email was sent by this script."
Write-Host "If both ports failed to connect, your network or cloud provider is very likely blocking outbound SMTP - see docs/TROUBLESHOOTING.md."