Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8588793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:53:27+00:00 2026-06-11T22:53:27+00:00

The following is my current code for connecting to gmail’s smtp server on port

  • 0

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.

My output from this program as it is, is:

220 mx.google.com ESMTP y10sm3296641yhd.6

250-mx.google.com at your service, [75.66.47.144]

250-SIZE 35882577

250-8BITMIME

250-STARTTLS

250 ENHANCEDSTATUSCODES

220 2.0.0 Ready to start TLS

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:53:29+00:00Added an answer on June 11, 2026 at 10:53 pm

    You can ssl wrap a connected socket. This will give you the idea:

    import ssl
    import base64
    from socket import *
    
    
    cc = socket(AF_INET, SOCK_STREAM)
    cc.connect(("smtp.gmail.com", 587))
    # cc.read(..)
    
    cc.send('helo tester.com\r\n')
    cc.send('starttls\r\n')
    # cc.read(..) If the server responds ok to starttls
    #             tls negotiation needs to happen and all
    #             communication is then over the SSL socket 
    
    scc = ssl.wrap_socket(cc, ssl_version=ssl.PROTOCOL_SSLv23)
    scc.send('auth login\r\n')
    # scc.read(..)
    
    scc.send(base64.b64encode('username')+'\r\n')
    scc.send(base64.b64encode('password')+'\r\n')
    
    # css.send(
    #  mail from:
    #  rcpt to:
    #  data
    #  etc
    

    look at the AUTH LOGIN section of this page for info about the username/password encoding: http://www.samlogic.net/articles/smtp-commands-reference-auth.htm

    After that the AUTH LOGIN command has been sent to the server, the
    server asks for username and password by sending BASE64 encoded text
    (questions) to the client. “VXNlcm5hbWU6” is the BASE64 encoded text
    for the word “Username” and “UGFzc3dvcmQ6” is the BASE64 encoded text
    for the word “Password” in the example above. The client sends
    username and password also using BASE64 encoding. “adlxdkej”, in the
    example above, is a BASE64 encoded username and “lkujsefxlj” is a
    BASE64 encoded password.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code, d has the current date. Depending on the current locale, it
I have following code return (EseshEntities.Current.Users.Select(u => new { Comunity = u.Apartment.Building.District.City })).ToList(); if
The following code summarizes the problem I have at the moment. My current execution
I am using following code to get current latitude and longitude. But none of
I have the following code that creates a submenu based on current document. The
I have this following code which will return all the current semesters. How do
I am using the following code to open a new Activity from my current
I want to get current alpha of textview i am using the following code
The Current Setup: So, I can use the following code to save a file
I'm trying to change the current selection of a NSTableView with the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.