crystal99 commited on
Commit
6c243e9
·
verified ·
1 Parent(s): 8458636

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -31
app.py CHANGED
@@ -1,35 +1,19 @@
1
- import smtplib
2
- import socket
3
- import threading
4
- import time
5
 
6
- HOST = 'localhost' # Replace with your desired hostname
7
- PORT = 25 # Standard SMTP port
8
 
9
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10
- server_socket.bind((HOST, PORT))
11
- server_socket.listen()
 
 
12
 
13
- def handle_client(client_socket, addr):
14
- while True:
15
- data = client_socket.recv(1024).decode()
16
- if not data:
17
- break
18
 
19
- # Process received data (e.g., parse commands, send responses)
20
- # ... (Implement your desired logic here)
21
-
22
- # Example: Respond to HELO/EHLO command
23
- if data.startswith('HELO') or data.startswith('EHLO'):
24
- response = f'250 {HOST} Ready'
25
- client_socket.send(response.encode())
26
-
27
- client_socket.close()
28
-
29
- while True:
30
- client_socket, addr = server_socket.accept()
31
- print('Connected by', addr)
32
-
33
- # Create a separate thread to handle the client
34
- client_thread = threading.Thread(target=handle_client, args=(client_socket, addr))
35
- client_thread.start()
 
1
+ from django.core.mail import get_connection
 
 
 
2
 
3
+ # Create a mail connection
4
+ connection = get_connection()
5
 
6
+ # Define a view to receive emails
7
+ def receive_email(request):
8
+ if request.method == 'POST':
9
+ # Get the email from the request
10
+ email = request.POST.get('email')
11
 
12
+ # Process the email
13
+ print(email['Subject'])
14
+ print(email['From'])
15
+ print(email['Body'])
 
16
 
17
+ return HttpResponse('Email received!')
18
+ else:
19
+ return HttpResponseNotAllowed(['POST'])