Using SMTP, Gmail, and STARTTLS

前端 未结 2 1170
离开以前
离开以前 2020-12-24 09:42

So I\'m learning about SMTP and am trying to use telnet to send some mail over SMTP.

I\'ve easilly been able to send mail to my gmail a

相关标签:
2条回答
  • 2020-12-24 09:52

    First of all, it looks like you're using the wrong port. Gmail exposes port 465 for SMTP over SSL and port 587 for SMTP with STARTTLS, as documented here. The difference between these two is that SMTP over SSL first establishes a secure SSL/TLS connection and conducts SMTP over that connection, and SMTP with STARTTLS starts with unencrypted SMTP and then switches to SSL/TLS. This is why you don't get 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 telnet to port 587 you still aren't going to be able to send any email by hand. In order to do anything interesting you will have to STARTTLS, and you won't be able to handle the SSL/TLS binary protocol to negotiate the encryption.

    0 讨论(0)
  • 2020-12-24 10:11

    The telnet client will not negotiate a TLS session for you. You should use another tool, such as OpenSSL's s_client. The following issues the STARTTLS command for you and handles the TLS negotiation:

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

    Alternatively, you could connect directly to the SMTPS port:

    $ openssl s_client -connect smtp.gmail.com:465 -crlf
    
    0 讨论(0)
提交回复
热议问题