Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import mod_html
- # import mailClient
- import sys
- import os
- import socket
- import time
- sys.stderr = sys.stdout
- def html(method,value):
- print ('''
- <!doctype html>
- <html>
- <head>
- <title>Say Hello</title>
- <meta charset = "utf-8">
- </head>
- <body>
- <h1> Hello </h1>
- <h2> Method = {0} </h2>
- <p>
- <form method="{0}" action="">
- <p> Sender Name: <input type="text" name="senderName" placeholder="Enter Name" value=""></p>
- <p> Sender Email Address: <input type="email" name="senderEmail" placeholder="Enter Email" value=""></p>
- <p> Recipient Name: <input type="text" name="recName" placeholder="Enter Name" value=""></p>
- <p> Recipient Email: <input type="email" name="recEmail" placeholder="Enter Email" value=""></p>
- <p> Email Subject: <input type="text" name="subject" placeholder="Enter Subject" value=""></p>
- <p> Email Body: <input type="text" name="body" placeholder="Enter Body" value=""></p>
- <p> <input type="submit" placeholder="Submit Email"></p>
- </form>
- </p>
- </body>
- </html> '''.format(method,value))
- def send_recv(socket, msg, code):
- if msg != None:
- print ("Sending==> ", msg)
- socket.send(msg.encode() + b'\r\n')
- def send(socket, msg):
- print("Sending ==> ", msg)
- socket.send(msg.encode() + b'\r\n')
- def sendMail(dataFromPost):
- serverName = 'smtp.cis.fiu.edu'
- serverPort = 25
- clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- clientSocket.settimeout(15)
- clientSocket.connect((serverName, serverPort))
- recv=send_recv(clientSocket, None, '220') # might need a loop to process all 220
- # data = cgi.FieldStorage()
- clientName = dataFromPost.get('senderName')
- userServer = "cs.fiu.edu"
- toServer = "fiu.edu"
- userName = dataFromPost.get('senderEmail')
- toName = dataFromPost.get('recEmail')
- subject = dataFromPost.get('subject')
- body = dataFromPost.get('body')
- #Send HELO command and print server response.
- heloCommand='EHLO %s' % clientName
- recvFrom = send_recv(clientSocket, heloCommand, '250')
- #Send MAIL FROM command and print server response.
- fromCommand='MAIL FROM: <%s>' % (userName)
- recvFrom = send_recv(clientSocket, fromCommand, '250')
- #Send RCPT TO command and print server response.
- rcptCommand='RCPT TO: <%s>' % (toName)
- recvRcpt = send_recv(clientSocket, rcptCommand, '250')
- #Send DATA command and print server response.
- dataCommand='DATA'
- dataRcpt = send_recv(clientSocket, dataCommand, '354')
- #Send message data.
- send(clientSocket, "Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S -0400", time.localtime()))
- send(clientSocket, "From: <%s>" % (userName))
- send(clientSocket, "Subject: %s" % subject)
- send(clientSocket, "To: %s" % (toName))
- send(clientSocket, ""); #End of headers
- send(clientSocket, body)
- #Message ends with a single period.
- send_recv(clientSocket, ".", '250')
- #Send QUIT command and get server response.
- quitCommand='QUIT'
- quitRcpt = send_recv(clientSocket, quitCommand, '221')
- def main():
- print('''Content-type: text/html\n''')
- value = ""
- parsed = mod_html.parse()
- html("post", parsed)
- if parsed:
- sendMail(parsed)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement