-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_email.py
More file actions
80 lines (60 loc) · 2.13 KB
/
test_email.py
File metadata and controls
80 lines (60 loc) · 2.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
"""
Simple test script to verify the SMTP server is working.
Run this script after starting the SMTP server with:
python manage.py run_smtp_server
This will send a test email to the local SMTP server.
"""
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from django.conf import settings
import os
import django
# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dripemails.settings')
django.setup()
def send_test_email():
"""Send a test email to the local SMTP server."""
# Email configuration
smtp_host = 'localhost'
smtp_port = 1025
# Create message
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = 'Test Email from DripEmails'
# Email body
body = """
Hello from DripEmails!
This is a test email sent to verify that the built-in SMTP server is working correctly.
Features of this setup:
- No external SMTP service required
- Perfect for development and testing
- All emails are displayed in the console
- No emails are actually sent to real recipients
Best regards,
DripEmails Team
"""
msg.attach(MIMEText(body, 'plain'))
try:
# Connect to SMTP server
server = smtplib.SMTP(smtp_host, smtp_port)
server.set_debuglevel(1) # Enable debug output
# Send email
text = msg.as_string()
server.sendmail(msg['From'], msg['To'], text)
print("✅ Test email sent successfully!")
print(f"📧 From: {msg['From']}")
print(f"📧 To: {msg['To']}")
print(f"📧 Subject: {msg['Subject']}")
print("\nCheck the SMTP server console to see the email content.")
server.quit()
except Exception as e:
print(f"❌ Error sending test email: {e}")
print("\nMake sure the SMTP server is running with:")
print("python manage.py run_smtp_server")
if __name__ == '__main__':
print("🧪 Testing DripEmails SMTP Server")
print("=" * 40)
send_test_email()