Using SMTP, Gmail, and STARTTLS

So, I learn about SMTP and try to use telnet to send mail through SMTP.

I could easily send mail to my gmail account with:

 $ host gmail.com ... gmail.com mail is handled by 5 gmail-smtp-in.l.google.com. ... $ telnet gmail-smtp-in.l.google.com 25 Trying 74.125.142.27... ... Connected to gmail-smtp-in.l.google.com. ... HELO < me@test.com > ... 

However, I am unable to send from my gmail account. From what I understand about SMTP, I have to use SMTP to send mail from < mygmailaddress@gmail.com > to outgoing gmail SMTP servers, which in turn use SMTP to send mail to the recipient of the incoming ect SMTP server.

However, I have difficulties. If I telnet to smtp.gmail.com through port 465 (gmail outgoing smtp canonical mail server), I immediately disconnected after starting with HELO < blah@blah.com > or asked STARTTLS . I can not find the answers to the question of how to proceed.

Any help is appreciated.

Sidenote: I am currently using Starbucks free Wi-Fi to access the Internet. Actually I cannot telnet directly from my computer (host routing error). Instead, it only works if I ssh in a remote Linux box on my school network, and then telnet from there. Any idea why this is?

Thanks!

+7
source share
2 answers

First of all, it looks like you are using the wrong port. Gmail provides port 465 for SMTP over SSL and port 587 for SMTP using STARTTLS, as described here . The difference between the two is that SMTP over SSL first establishes a secure SSL / TLS connection and conducts SMTP over that connection, while SMTP with STARTTLS starts with plaintext SMTP and then switches to SSL / TLS. That is why you do not receive a response to your HELO.

 $ telnet smtp.gmail.com 587 Trying 74.125.25.108... Connected to gmail-smtp-msa.l.google.com. Escape character is '^]'. 220 mx.google.com ESMTP fr1sm24834956pbb.26 - gsmtp HELO < me@test.com > 250 mx.google.com at your service STARTTLS 220 2.0.0 Ready to start TLS 

But even if you connect to port 587, you still cannot send any messages manually. To do something interesting, you have to have STARTTLS , and you will not be able to process the SSL / TLS binary protocol to negotiate encryption.

+21
source

The telnet client will not negotiate a TLS session. You should use another tool like OpenSSL s_client. The following issues trigger the STARTTLS command for you and process the TLS negotiation:

 $ openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf 

Alternatively, you can directly connect to the SMTPS port:

 $ openssl s_client -connect smtp.gmail.com:465 -crlf 
+15
source

All Articles