Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to start TLS on an active connection in python?
    primarykey
    data
    text
    <p>The following is my current code for connecting to gmail's smtp server on port 587. After issuing the STARTTLS command how would I finish negotiating the TLS session and begin issuing commands such as AUTH LOGIN and MAIL FROM? I have ommitted my Base64 encoded gmail username and replaced it with xxxxxxxx near the bottom of my code.</p> <p>My output from this program as it is, is: </p> <blockquote> <p>220 mx.google.com ESMTP y10sm3296641yhd.6</p> <p>250-mx.google.com at your service, [75.66.47.144]</p> <p>250-SIZE 35882577</p> <p>250-8BITMIME</p> <p>250-STARTTLS</p> <p>250 ENHANCEDSTATUSCODES</p> <p>220 2.0.0 Ready to start TLS</p> </blockquote> <pre><code>from socket import * import ssl msg = "\r\n smtp.." endmsg = "\r\n.\r\n" # Mailserver hostname and port to be used. mailserver = ("smtp.gmail.com", 587) # Create a socket and create an active TCP connection with the mailserver clientSocket = socket(AF_INET, SOCK_STREAM); clientSocket.connect(mailserver) # Read server response recv = clientSocket.recv(1024) print recv if recv[:3] != '220': print '220 reply not received from server.' # Send EHLO command and print server response. ehloCommand = 'EHLO smtp.google.com\r\n' clientSocket.send(ehloCommand) recv1 = clientSocket.recv(1024) print recv1 if recv1[:3] != '250': print '250 reply not received from server.' # Send STARTTLS command to server and print server response command = "STARTTLS\r\n" clientSocket.send(command) recv1 = clientSocket.recv(1024) print recv1 if recv[:3] != '220': print '220 reply not received from server.' # SEND AUTH LOGIN command and Base64 encoded username command = "AUTH LOGIN xxxxxxxxxxxxx\r\n" clientSocket.send(command) recv1 = clientSocket.recv(1024) print recv1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload