4

I have a situation. I want to connect to gmail smtp server and send Email from my gmail account. as gmail smtp server uses PLAIN authentication and TLS. I connect to gmail smtp server. and server response is as follow.

220 mx.google.com ESMTP n21sm810716wed.43

then I send it "AUTH PLAIN" and send "EHLO" command. The server responses are as follow:

503 5.5.1 EHLO/HELO first. n21sm810716wed.43

I then sent it "EHLO" command again and response is:

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

after this whatever I give it. It prints a sequence of line and Exit. The sequence of responses which it gives are;

250-SIZE 35882577

250-8BITMIME

250-STARTTLS

250 ENHANCEDSTATUSCODES

what should I give it so that it let me login and send me Email? Any help or suggestion will be appreciated. Thanks

See also

Using SMTP, Gmail, and STARTTLS

Community
  • 1
  • 1
Ali Ahmed
  • 1,749
  • 6
  • 20
  • 29
  • 1
    You tagged your question with "c", but there are no references to C code. Are you writing a C program to connect to a SMTP server? Are you using any library? – Danilo Piazzalunga Aug 01 '11 at 21:28

3 Answers3

4

You are facing 3 problems:

First, you are not reading entire response of EHLO command.

This command has multi-line response:

250-mx.google.com at your service, [203.99.179.10] 
250-SIZE 35882577 
250-8BITMIME 
250-STARTTLS 
250 ENHANCEDSTATUSCODES

Note the space after last 250 code - it means that this is the last response line.

Second: EHLO should be the first command you send.

Third: Gmail does not allow to log-in without using SSL, either implicit (on 465 port) or explicit (STARTTLS command)

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
Pawel Lesnikowski
  • 6,264
  • 4
  • 38
  • 42
  • 2
    I am reading the entire response of Ehlo command. the Ehlo is the first command that I am sending. after these responses I sent it STARTTLS and server response "220 2.0.0 Ready to start TLS" but whatever I sent after this server quit. I have no idea Where I am making mistake or missing something? – Ali Ahmed Jul 29 '11 at 07:16
2

We can not use STARTTLS unless we have a secure connection with the server. simple SMTP library and telnet do not support STARTTLS. For this I had to use GNUTLS which performs handshaking with the server and exchange certificate to establish a secure connection. After that I send STARTTLS and it works fine. Hope this helps other facing similar problem. Thanks

Ali Ahmed
  • 1,749
  • 6
  • 20
  • 29
0

You should issue the STARTTLS command after the given response. Here is an SMTP conversation example, obtained with netcat on smtp.gmail.com on port 587:

220 mx.google.com ESMTP z83sm46627weq.20
EHLO localhost
250-mx.google.com at your service, [109.114.60.32]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
STARTTLS
220 2.0.0 Ready to start TLS
Danilo Piazzalunga
  • 7,590
  • 5
  • 49
  • 75
  • 1
    I issued STARTTLS command and get response "220 2.0.0 Ready to start TLS". But whatever I enter after that the server sent me the quit reply. Why is that?? Am I doing something wrong? – Ali Ahmed Jul 28 '11 at 06:24
  • @Ali Do you start to use SSL after you issue STARTTLS command? – Pawel Lesnikowski Jul 28 '11 at 14:06
  • @Pawel Lesnikowski I did not understand what is mean by "use SSL". after STARTTLS I simply continue sending data on the same socket without and modification of step. Can you please explain it? – Ali Ahmed Jul 29 '11 at 04:31
  • 1
    It means starting the TLS handshake. After that, all data sent and received is encrypted: see http://en.wikipedia.org/wiki/Transport_Layer_Security. After STARTTLS, you have to reissue the EHLO command, and then proceed authenticating with the AUTH command: see http://en.wikipedia.org/wiki/SMTP_Authentication and http://tools.ietf.org/html/rfc4954 – Danilo Piazzalunga Aug 01 '11 at 21:26