Test IMAP login

Signs in to a mailbox and lists the folders: checks reachability, credentials and permission in one go.

IMAPS (993)

PowerShell (Windows)

SslStream (.NET) Built-in

$h = "mail.example.com"; $p = 993
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
$r = New-Object IO.StreamReader($ssl)
$w = New-Object IO.StreamWriter($ssl); $w.NewLine = "`r`n"; $w.AutoFlush = $true
$r.ReadLine()
$w.WriteLine('a1 LOGIN user@example.com "P@ssw0rd"'); $r.ReadLine()
$w.WriteLine("a2 LIST \"\" *"); Start-Sleep -Milliseconds 400; while ($c.Available) { $r.ReadLine() }
$w.WriteLine("a3 LOGOUT"); $c.Close()

openssl Add-on tool

openssl s_client -crlf -connect mail.example.com:993

Unix shell (bash)

openssl Built-in

openssl s_client -crlf -quiet -connect mail.example.com:993 <<'EOF'
a1 LOGIN user@example.com "P@ssw0rd"
a2 LIST "" *
a3 LOGOUT
EOF

curl Add-on tool

curl -v --url "imaps://mail.example.com:993" --user "user@example.com"

Microsoft 365

PowerShell (Windows)

SslStream (.NET) Built-in

$h = "outlook.office365.com"; $p = 993
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
$r = New-Object IO.StreamReader($ssl)
$w = New-Object IO.StreamWriter($ssl); $w.NewLine = "`r`n"; $w.AutoFlush = $true
$r.ReadLine()
$w.WriteLine('a1 LOGIN user@contoso.com "P@ssw0rd"'); $r.ReadLine()
$w.WriteLine("a2 LIST \"\" *"); Start-Sleep -Milliseconds 400; while ($c.Available) { $r.ReadLine() }
$w.WriteLine("a3 LOGOUT"); $c.Close()

openssl Add-on tool

openssl s_client -crlf -connect outlook.office365.com:993

Unix shell (bash)

openssl Built-in

openssl s_client -crlf -quiet -connect outlook.office365.com:993 <<'EOF'
a1 LOGIN user@contoso.com "P@ssw0rd"
a2 LIST "" *
a3 LOGOUT
EOF

curl Add-on tool

curl -v --url "imaps://outlook.office365.com:993" --user "user@contoso.com"

Replace P@ssw0rd with the real password. Microsoft 365 has disabled basic authentication for IMAP; there it needs OAuth 2.0, so a plain LOGIN attempt fails as expected.

IMAP capabilities

Shows the capabilities the server advertises, including the supported authentication methods (AUTH=PLAIN, AUTH=XOAUTH2 ...).

IMAPS (993)

PowerShell (Windows)

SslStream (.NET) Built-in

$h = "mail.example.com"; $p = 993
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
$r = New-Object IO.StreamReader($ssl)
$w = New-Object IO.StreamWriter($ssl); $w.NewLine = "`r`n"; $w.AutoFlush = $true
$r.ReadLine()
$w.WriteLine("a1 CAPABILITY"); Start-Sleep -Milliseconds 300; while ($c.Available) { $r.ReadLine() }
$w.WriteLine("a2 LOGOUT"); $c.Close()

openssl Add-on tool

openssl s_client -crlf -connect mail.example.com:993

Unix shell (bash)

openssl Built-in

printf 'a1 CAPABILITY\r\na2 LOGOUT\r\n' | openssl s_client -crlf -quiet -connect mail.example.com:993 2>/dev/null

curl Add-on tool

curl -sv --url "imaps://mail.example.com:993" 2>&1 | grep -i capability

Mailbox status

Queries the message and unseen count in the inbox: useful to confirm delivery.

PowerShell (Windows)

SslStream (.NET) Built-in

$h = "mail.example.com"; $p = 993
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
$r = New-Object IO.StreamReader($ssl)
$w = New-Object IO.StreamWriter($ssl); $w.NewLine = "`r`n"; $w.AutoFlush = $true
$r.ReadLine()
$w.WriteLine('a1 LOGIN user@example.com "P@ssw0rd"'); $r.ReadLine()
$w.WriteLine("a2 STATUS INBOX (MESSAGES UNSEEN)"); Start-Sleep -Milliseconds 400; while ($c.Available) { $r.ReadLine() }
$w.WriteLine("a3 LOGOUT"); $c.Close()

curl Add-on tool

curl.exe -v --url "imaps://mail.example.com:993/INBOX" --user "user@example.com" --request "STATUS INBOX (MESSAGES UNSEEN)"

Unix shell (bash)

openssl Built-in

openssl s_client -crlf -quiet -connect mail.example.com:993 <<'EOF'
a1 LOGIN user@example.com "P@ssw0rd"
a2 STATUS INBOX (MESSAGES UNSEEN)
a3 LOGOUT
EOF

curl Add-on tool

curl --url "imaps://mail.example.com:993/INBOX" --user "user@example.com" --request "STATUS INBOX (MESSAGES UNSEEN)"

Replace P@ssw0rd with the real password.

Test POP3

Signs in via POP3 and uses STAT to query the number and size of waiting messages.

PowerShell (Windows)

SslStream (.NET) Built-in

$h = "mail.example.com"; $p = 995
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
$r = New-Object IO.StreamReader($ssl)
$w = New-Object IO.StreamWriter($ssl); $w.NewLine = "`r`n"; $w.AutoFlush = $true
$r.ReadLine()
$w.WriteLine("USER user@example.com"); $r.ReadLine()
$w.WriteLine("PASS P@ssw0rd"); $r.ReadLine()
$w.WriteLine("STAT"); $r.ReadLine()
$w.WriteLine("QUIT"); $c.Close()

openssl Add-on tool

openssl s_client -crlf -connect mail.example.com:995

Unix shell (bash)

openssl Built-in

openssl s_client -crlf -quiet -connect mail.example.com:995 <<'EOF'
USER user@example.com
PASS P@ssw0rd
STAT
QUIT
EOF

curl Add-on tool

curl -v --url "pop3s://mail.example.com:995" --user "user@example.com"

Replace P@ssw0rd with the real password. Depending on the client, POP3 deletes messages after retrieval; a plain STAT test does not.

IMAP STARTTLS (143)

Establishes a STARTTLS connection on the clear-text port 143 and shows the certificate.

PowerShell (Windows)

TcpClient (.NET) Built-in

$c = New-Object Net.Sockets.TcpClient("mail.example.com", 143)
$s = $c.GetStream()
$r = New-Object IO.StreamReader($s)
$w = New-Object IO.StreamWriter($s); $w.NewLine = "`r`n"; $w.AutoFlush = $true
$r.ReadLine()
$w.WriteLine("a1 STARTTLS"); $r.ReadLine()
$ssl = New-Object Net.Security.SslStream($s, $false, ({ $true }))
$ssl.AuthenticateAsClient("mail.example.com")
([Security.Cryptography.X509Certificates.X509Certificate2]$ssl.RemoteCertificate) | Format-List Subject, NotAfter
$ssl.Dispose(); $c.Close()

openssl Add-on tool

openssl s_client -starttls imap -crlf -connect mail.example.com:143

Unix shell (bash)

openssl Built-in

openssl s_client -starttls imap -connect mail.example.com:143 </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates

curl Add-on tool

curl -v --url "imap://mail.example.com:143" --ssl-reqd

Other areas