Sending Email to Gmail's SMTP server using TLS and Plain Authentication

19,872

Solution 1

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

Solution 2

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)

Share:
19,872
Ali Ahmed
Author by

Ali Ahmed

Software Developer

Updated on June 04, 2022

Comments

  • Ali Ahmed
    Ali Ahmed over 1 year

    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