Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import mod_html
  4. # import mailClient
  5. import sys
  6. import os
  7. import socket
  8. import time
  9.  
  10. sys.stderr = sys.stdout
  11.  
  12. def html(method,value):
  13. print ('''
  14. <!doctype html>
  15. <html>
  16. <head>
  17. <title>Say Hello</title>
  18. <meta charset = "utf-8">
  19. </head>
  20. <body>
  21. <h1> Hello </h1>
  22. <h2> Method = {0} </h2>
  23. <p>
  24. <form method="{0}" action="">
  25. <p> Sender Name: <input type="text" name="senderName" placeholder="Enter Name" value=""></p>
  26. <p> Sender Email Address: <input type="email" name="senderEmail" placeholder="Enter Email" value=""></p>
  27. <p> Recipient Name: <input type="text" name="recName" placeholder="Enter Name" value=""></p>
  28. <p> Recipient Email: <input type="email" name="recEmail" placeholder="Enter Email" value=""></p>
  29. <p> Email Subject: <input type="text" name="subject" placeholder="Enter Subject" value=""></p>
  30. <p> Email Body: <input type="text" name="body" placeholder="Enter Body" value=""></p>
  31. <p> <input type="submit" placeholder="Submit Email"></p>
  32. </form>
  33. </p>
  34. </body>
  35. </html> '''.format(method,value))
  36.  
  37. def send_recv(socket, msg, code):
  38. if msg != None:
  39. print ("Sending==> ", msg)
  40. socket.send(msg.encode() + b'\r\n')
  41.  
  42. def send(socket, msg):
  43. print("Sending ==> ", msg)
  44. socket.send(msg.encode() + b'\r\n')
  45.  
  46. def sendMail(dataFromPost):
  47. serverName = 'smtp.cis.fiu.edu'
  48. serverPort = 25
  49.  
  50. clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  51. clientSocket.settimeout(15)
  52.  
  53. clientSocket.connect((serverName, serverPort))
  54. recv=send_recv(clientSocket, None, '220') # might need a loop to process all 220
  55.  
  56. # data = cgi.FieldStorage()
  57. clientName = dataFromPost.get('senderName')
  58. userServer = "cs.fiu.edu"
  59. toServer = "fiu.edu"
  60. userName = dataFromPost.get('senderEmail')
  61. toName = dataFromPost.get('recEmail')
  62. subject = dataFromPost.get('subject')
  63. body = dataFromPost.get('body')
  64.  
  65. #Send HELO command and print server response.
  66. heloCommand='EHLO %s' % clientName
  67. recvFrom = send_recv(clientSocket, heloCommand, '250')
  68. #Send MAIL FROM command and print server response.
  69. fromCommand='MAIL FROM: <%s>' % (userName)
  70. recvFrom = send_recv(clientSocket, fromCommand, '250')
  71. #Send RCPT TO command and print server response.
  72. rcptCommand='RCPT TO: <%s>' % (toName)
  73. recvRcpt = send_recv(clientSocket, rcptCommand, '250')
  74. #Send DATA command and print server response.
  75. dataCommand='DATA'
  76. dataRcpt = send_recv(clientSocket, dataCommand, '354')
  77. #Send message data.
  78. send(clientSocket, "Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S -0400", time.localtime()))
  79. send(clientSocket, "From: <%s>" % (userName))
  80. send(clientSocket, "Subject: %s" % subject)
  81. send(clientSocket, "To: %s" % (toName))
  82. send(clientSocket, ""); #End of headers
  83. send(clientSocket, body)
  84. #Message ends with a single period.
  85. send_recv(clientSocket, ".", '250')
  86. #Send QUIT command and get server response.
  87. quitCommand='QUIT'
  88. quitRcpt = send_recv(clientSocket, quitCommand, '221')
  89.  
  90. def main():
  91. print('''Content-type: text/html\n''')
  92. value = ""
  93. parsed = mod_html.parse()
  94. html("post", parsed)
  95. if parsed:
  96. sendMail(parsed)
  97. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement