You can run that test code directly in your local machine using a Python shell or by saving it into a .py
file and running it from the terminal.
✅ Option 1: Run it in Python Shell (REPL)
- Open your terminal or command prompt.
- Start the Python shell:
python
- Paste the code line by line:
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'axifabumqxffftmnuyf')
print("Login success!")
server.quit()
If it prints Login success!
, the SMTP connection is working, and the issue is likely within your Django project config or a firewall block specific to that process.
✅ Option 2: Save and Run as a Python File
- Create a file, e.g.,
smtp_test.py
. - Paste the code:
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'axifabumqxffftmnuyf')
print("Login success!")
server.quit()
- Run it in your terminal:
python smtp_test.py
✅ Option 3: Save and Run as a Python File
To test if Django can send mail:
python manage.py shell
Then paste:
from django.core.mail import send_mail
send_mail(
'Test Subject',
'This is the test message.',
'[email protected]', # From email
['[email protected]'], # To email
fail_silently=False
)
If it succeeds, you’ll get an email. If it fails, it will show the real error.
🔍 What This Tells You
- If it succeeds, your credentials and Gmail settings are correct, and the issue lies in how Django is attempting to connect (firewall, TLS settings, or environmental variable parsing).
- If it fails with the same
ConnectionRefusedError
, your local machine is blocking the connection — usually a firewall, antivirus, or network setting.
Top comments (0)