When attempting to use telnet with port 465 (SMTPS), you're encountering immediate disconnection because:
- Port 465 requires SSL/TLS encryption from the first byte
- Basic telnet doesn't support encrypted connections
- Modern SMTP servers enforce immediate security protocols
Instead of telnet, use these alternatives for port 465:
# Using openssl (recommended)
openssl s_client -connect smtp.gmail.com:465 -crlf -quiet
# Using stunnel (alternative)
stunnel -c -d localhost:2525 -r smtp.gmail.com:465
telnet localhost 2525
Here's how a successful session should look with openssl:
$ openssl s_client -connect smtp.gmail.com:465 -crlf -quiet
220 smtp.gmail.com ESMTP xxxxxxxxxxxxxx
EHLO example.com
250-smtp.gmail.com at your service
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
AUTH LOGIN
334 VXNlcm5hbWU6
[base64-encoded username]
334 UGFzc3dvcmQ6
[base64-encoded password]
235 2.7.0 Accepted
MAIL FROM: <sender@example.com>
250 2.1.0 OK
RCPT TO: <recipient@gmail.com>
250 2.1.5 OK
DATA
354 Go ahead
Subject: Test email
From: sender@example.com
To: recipient@gmail.com
This is a test message.
.
250 2.0.0 OK
QUIT
221 2.0.0 closing connection
Authentication Errors: Ensure you've enabled "Less secure apps" in Google Account settings or use App Passwords if 2FA is enabled.
Connection Timeouts: Many ISPs block outbound port 465. Test with port 587 (submission) instead:
openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf
For frequent testing, consider this bash script:
#!/bin/bash
{
sleep 1
echo "EHLO $(hostname)"
sleep 1
echo "AUTH LOGIN"
sleep 1
echo "$(echo -n 'your@email.com' | base64)"
sleep 1
echo "$(echo -n 'yourpassword' | base64)"
sleep 1
echo "MAIL FROM: <your@email.com>"
sleep 1
echo "RCPT TO: <recipient@domain.com>"
sleep 1
echo "DATA"
sleep 1
echo "Subject: Test Email"
echo ""
echo "This is an automated test email."
echo "."
sleep 1
echo "QUIT"
} | openssl s_client -connect smtp.gmail.com:465 -crlf -quiet
When attempting to use telnet directly on port 465 (SMTPS), you'll encounter immediate disconnection because:
$ telnet smtp.gmail.com 465
Trying 108.177.126.108...
Connected to smtp.gmail.com.
Escape character is '^]'.
Connection closed by foreign host
Port 465 requires SSL/TLS encryption from the first byte - traditional telnet can't establish the secure layer. Here's what's happening under the hood:
- The SMTP server expects TLS handshake immediately
- Telnet sends plaintext commands instead
- Server terminates the connection for security
Option 1: Use openssl instead of telnet
The proper way to manually test SMTP over port 465:
openssl s_client -connect smtp.gmail.com:465 -crlf -quiet
Example session:
EHLO example.com
AUTH LOGIN
[base64-encoded-username]
[base64-encoded-password]
MAIL FROM: <test@example.com>
RCPT TO: <recipient@gmail.com>
DATA
Subject: Test email
This is a test message.
.
QUIT
Option 2: Use port 587 with STARTTLS
For servers supporting STARTTLS (port 587):
openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf
Option 3: Use swaks (Swiss Army Knife for SMTP)
Install and run:
swaks --to recipient@example.com \
--from test@example.com \
--server smtp.gmail.com:465 \
--tlsc \
--auth-user your@gmail.com \
--auth-password 'yourpass'
- Always check if your IP isn't blocked (common with Gmail)
- Enable "Less secure apps" if using Gmail (or use App Password)
- Verify firewall isn't blocking outbound 465
- Check server logs for connection attempts
Here's a complete test session with annotations:
# Establish connection
openssl s_client -connect smtp.example.com:465 -crlf -quiet
# Server responds with banner
220 smtp.example.com ESMTP Service Ready
# Identify yourself
EHLO client.example.com
250-smtp.example.com Hello [192.0.2.1]
250-SIZE 35882577
250-STARTTLS
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
# Authenticate
AUTH PLAIN [base64-encoded-credentials]
235 2.7.0 Authentication successful
# Compose email
MAIL FROM:<sender@example.com>
250 2.1.0 Sender OK
RCPT TO:<recipient@example.com>
250 2.1.5 Recipient OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Subject: SMTP/S Test
From: Sender <sender@example.com>
To: Recipient <recipient@example.com>
This message was sent via SMTPS.
.
250 2.0.0 OK 1234567890 qp12345
# Clean exit
QUIT
221 2.0.0 Closing connection