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 8727325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:24:57+00:00 2026-06-13T08:24:57+00:00

I am attempting to connect to the Gmail SMTP mail server and perform tasks

  • 0

I am attempting to connect to the Gmail SMTP mail server and perform tasks as outlined by the skeleton code given to me. Only the use of sockets is allowed (so not the smtplib). I need to: send HELO command, MAIL FROM, RCPT TO, and DATA.

There are many cases of similar problems posted, but they haven’t received the proper answer. For example:
Implementing Transport Layer Security in Python – Simple Mail Client

The program is required to connect to smtp.gmail.com over port 587. I’ve taken two different approaches:

  1. Using STARTTLS:

    mailserver = 'smtp.gmail.com'
    clientSocket = socket(AF_INET, SOCK_STREAM)
    clientSocket.connect((mailserver, 587))
    recv = clientSocket.recv(1024)
    print recv
    if recv[:3] != '220':
        print '220 reply not received from server.'
    
    #Send HELO command and print server response
    heloCommand = 'HELO Alice\r\n'
    clientSocket.send(heloCommand)
    recv1 = clientSocket.recv(1024)
    print recv1
    if recv1[:3] != '250':
        print '250 reply not received from server.'
    
    #Send MAIL FROM command and print server response.
    command = "STARTTLS\r\n"
    clientSocket.send(command)
    recvdiscard = clientSocket.recv(1024)
    print recvdiscard
    clientSocket.send("MAIL From: email\r\n")
    recv2 = clientSocket.recv(1024)
    print recv2
    if recv2[:3] != '250':
        print '250 reply not received from server.'
    
  2. Using SSL:

    clientSocketSSL = ssl.wrap_socket(clientSocket)
    

    Then clientSocketSSL replaces all instances of clientSocket. The STARTTLS lines are also removed and import ssl is added to the top.

When using the first method, the MAIL FROM: command isn’t returning anything. I’m getting the following output:

250 mx.google.com at your service

220 2.0.0 Ready to start TLS

250 reply not received from server.

When using SSL, I’m getting the same as the linked post:

ssl.SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

Am I missing something here? I guess my best option is to use TLS but I have no idea how to go about that… is there something wrong with my MAIL FROM command?

  • 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-13T08:24:58+00:00Added an answer on June 13, 2026 at 8:24 am

    When using SSL, you need to connect to port 465 instead of port 587. If you use STARTTLS, you still need to use ssl.wrap_socket, you just do it later – specifically, after receiving the 220 response to the STARTTLS command. After doing STARTTLS, you’re supposed to do HELO again, since the server is supposed to forget anything that happened before the STARTTLS.

    In either case, the servers at smtp.google.com ports 465 and 587 still won’t return a 250 response to the MAIL command, since they require that you are authenticated before you send mail. You’ll get a 530 response instead. You’ll need to use the AUTH command with your gmail.com credentials to authenticate before you can use MAIL successfully on those servers.

    If you don’t want to authenticate, and depending on the details of what you need to do, you could try using port 25 of the server found in gmail.com’s MX record. At the moment, the server is gmail-smtp-in.l.google.com and supports STARTTLS.

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

Sidebar

Related Questions

I am attempting to connect to my local MySQL server with the following code:
I'm attempting to connect to our exchange server using Mail::IMAPClient but a script that
I am attempting to connect to a Microsoft SQL server db using PHP (in
I am getting the below error when attempting to connect to a Sybase server
I am attempting to connect to a SQL Server 2008 R2 instance from another
I am attempting to connect to a remote MySQL server from my local machine
I am attempting to connect to Microsoft SQL Server 2008 R2 from within Microsoft
I'm attempting to connect to a remote server, which I'll refer to as machine
I'm able to ping the remote server I am attempting to connect to successfully.
I attempting to connect to a server via PHP fsockopen to initially get a

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.