---
title: How to test connection to SMTP server
slug: user-guide-10x/how-to-test-connection-to-smtp-server
docTags: 
createdAt: 2025-12-12T11:59:28.175Z
---

Use the commands/script below to test the connection to an SMTP server.

## Test connection to SMTP server

To connect using the TLS protocol on port 587, use:

:::BlockQuote
$ openssl s\_client -starttls smtp -connect \<SMTP\_SERVER>:587
:::

To use SSL on port 465:

:::BlockQuote
$ openssl s\_client -connect \<SMTP\_SERVER>:465
:::

## Test SMTP server credentials and send test email

NOTE: Uses python3

:::BlockQuote
import smtplib, ssl
from getpass import getpass
from email.message import EmailMessage

port = 25  # 465 SSL, or 587 TLS
server = '\<SMTP SERVER OR IP>'
sender  = '\<SMTP EMAIL>'
password = getpass('Type the password and press enter: ')
recipient = '\<RECIPIENT EMAIL>'

msg = EmailMessage()
msg\['Subject'] = 'SMTP e-mail test'
msg\['From'] = sender
msg\['To'] = recipient
msg.set\_content('This is a test e-mail message.')

context = ssl.create\_default\_context()

print("------------------------")
print("Test connection with SSL")
print("------------------------")

try:
&#x20;   smtp = smtplib.SMTP\_SSL(server, port, context=context)
&#x20;   smtp.login(sender, password)
&#x20;   print("Connection successful") &#x20;
&#x20;   \#smtp.send\_message(msg)
&#x20;   \#print("Email sent successfully. Check and confirm!")
except Exception as e:
&#x20;   print(e)

print("\n")
print("---------------------------")
print("Test connection without SSL")
print("---------------------------")

try:
&#x20;   smtp = smtplib.SMTP(server, port)
&#x20;   smtp.login(sender, password)
&#x20;   print("Connection successful") &#x20;
&#x20;   \#smtp.send\_message(msg)
&#x20;   \#print("Email sent successfully. Check and confirm!")
except Exception as e:
&#x20;   print(e)

print("------------------------")
print("Test connection with TLS/SSL")
print("------------------------")

try:
&#x20;   smtp = smtplib.SMTP(server, port)
&#x20;   smtp.starttls(context=context)
&#x20;   smtp.login(sender, password)
&#x20;   print("Connection successful") &#x20;
&#x20;   \#smtp.send\_message(msg)
&#x20;   \#print("Email sent successfully. Check and confirm!")
except Exception as e:
&#x20;   print(e)
&#x20;  &#x20;
:::

