title: Mail Client in Python using sockets only(no smtplib)
body: <p>I am trying to write a python program which will send emails without using smtplib. I have tried to look other posts on this but could not find a solution. </p>
  
  <pre><code>`from socket import *
  
  
  msg = "\r\n My email's content!"
  endmsg = "\r\n.\r\n"
  
  mailserver = ("smtp.aol.com", 25) 
  
  clientSocket = socket(AF_INET, SOCK_STREAM)
  clientSocket.connect(mailserver)
  
  recv = clientSocket.recv(1024)
  recv = recv.decode()
  print("Message after connection request:" + recv)
  if recv[:3] != '220':
      print('220 reply not received from server.')
  heloCommand = 'HELO Alice\r\n'
  clientSocket.send(heloCommand.encode())
  recv1 = clientSocket.recv(1024)
  recv1 = recv1.decode()
  print("Message after HeLO command:" + recv1)
  if recv1[:3] != '250':
      print('250 reply not received from server.')
  
  # #Info for username and password
  # username = "myusername"
  # password = "xxxxxxxx"
  # authMsg = "AUTH LOGIN\r\n"
  # clientSocket.send(authMsg.encode())
  # recv_auth = clientSocket.recv(1024)
  # print(recv_auth.decode())
  
  # clientSocket.send(username.encode())
  # clientSocket.send("\r\n".encode())
  # recv_user = clientSocket.recv(1024)
  # print("Response after sending username: "+recv_user.decode())
  
  # clientSocket.send(password.encode())
  # clientSocket.send("\r\n".encode())
  # recv_pass = clientSocket.recv(1024)
  # print("Response after sending password: "+recv_pass.decode())
  
  
  # clientSocket.send(('starttls\r\n').encode())
  # recv_tls = clientSocket.recv(1024)
  # print(recv_tls.decode())
  
  
  
  mailFrom = "MAIL FROM:&lt;yjorayev@aol.com&gt;\r\n"
  clientSocket.send(mailFrom.encode())
  recv2 = clientSocket.recv(1024)
  recv2 = recv2.decode()
  print("After MAIL FROM command: "+recv2)
  
  rcptTo = "RCPT TO:&lt;ijorayev@gmail.com&gt;\r\n"
  clientSocket.send(rcptTo.encode())
  recv3 = clientSocket.recv(1024)
  recv3 = recv3.decode()
  print("After RCPT TO command: "+recv3)
  
  data = "DATA\r\n"
  clientSocket.send(data.encode())
  recv4 = clientSocket.recv(1024)
  recv4 = recv4.decode()
  print("After DATA command: "+recv4)
  
  clientSocket.send(msg.encode())
  
  clientSocket.send(endmsg.encode())
  recv_msg = clientSocket.recv(1024)
  print("Response after sending message body:"+recv_msg.decode())
  
  quit = "QUIT\r\n"
  clientSocket.send(quit.encode())
  recv5 = clientSocket.recv(1024)
  print(recv5.decode())
  clientSocket.close()` 
  </code></pre>
  
  <p>Is it possible to send an email without logging in to server? If not how do I login correctly? Every time I tried to log in I have received  "authentication failed" error. I also have errors saying "Need MAIL command" and "Need RCPT command" even though I am sending MAIL FROM and RCPT TO commands. </p>