forked from yousumohamed/Sendpilot-email-bulk-message
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_smtp_diag.py
More file actions
54 lines (45 loc) · 1.7 KB
/
test_smtp_diag.py
File metadata and controls
54 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import smtplib
from email.message import EmailMessage
from decouple import config
def test_smtp():
# Load from .env
host = config('SMTP_HOST', default='smtp.gmail.com')
port = config('SMTP_PORT', default=587, cast=int)
user = config('SMTP_USER', default='')
password = config('SMTP_PASSWORD', default='')
print(f"--- SMTP Diagnostic Test ---")
print(f"Host: {host}")
print(f"Port: {port}")
print(f"User: {user}")
print(f"Password: {'*' * len(password)}")
print("-" * 30)
msg = EmailMessage()
msg.set_content("This is a test email from your local Bulk Email Dashboard.")
msg['Subject'] = "SMTP Test Connection"
msg['From'] = user
msg['To'] = user
try:
print("Connecting to server...")
server = smtplib.SMTP(host, port)
server.set_debuglevel(1)
print("Starting TLS...")
server.starttls()
print(f"Attempting login for {user}...")
server.login(user, password)
print("Login successful!")
server.send_message(msg)
print("Test email sent successfully!")
server.quit()
return True
except smtplib.SMTPAuthenticationError:
print("\n❌ ERROR: Authentication Failed (535)")
print("This means Gmail rejected your credentials.")
print("1. Ensure 'SMTP_USER' is your full email address.")
print("2. Ensure 'SMTP_PASSWORD' is a 16-character APP PASSWORD, not your login password.")
print("3. Check if 2-Factor Authentication is enabled on your Google Account.")
except Exception as e:
print(f"\n❌ ERROR: {str(e)}")
return False
if __name__ == "__main__":
test_smtp()