Hi,
Here's a simple PowerShell script that you can use to simulate a connection to an SMTP server and check its status:
# Define SMTP server and port
$smtpServer = "smtp.yourserver.com"
$smtpPort = 25
# Create a TCP client to connect to the SMTP server
$tcpClient = New-Object System.Net.Sockets.TcpClient
try {
# Attempt to connect to the SMTP server
$tcpClient.Connect($smtpServer, $smtpPort)
if ($tcpClient.Connected) {
Write-Output "Successfully connected to SMTP server $smtpServer on port $smtpPort."
} else {
Write-Output "Failed to connect to SMTP server $smtpServer on port $smtpPort."
}
} catch {
Write-Output "Error: $_"
} finally {
# Close the TCP client connection
$tcpClient.Close()
}
This script attempts to connect to the specified SMTP server and port. If the connection is successful, it will output a success message; otherwise, it will output a failure message or any error encountered.
Feel free to modify the $smtpServer
and $smtpPort
variables to match your SMTP server's details. Let me know if you need any further assistance!