Connecting to smtp.gmail.com via command line

后端 未结 10 2386
粉色の甜心
粉色の甜心 2020-12-07 16:42

I am in the process of writing an application that sends mail via an valid GMail user ID and password.

I just wanted to simulate the SMTP connection on my Windows XP

10条回答
  •  清歌不尽
    2020-12-07 17:01

    Using Linux or OSx, do what Sorin recommended but use port 465 instead. 25 is the generic SMTP port, but not what GMail uses. Also, I don't believe you want to use -starttls smtp

    openssl s_client -connect smtp.gmail.com:465
    

    You should get lots of information on the SSL session and the response:

    220 mx.google.com ...
    

    Type in

    HELO smtp.gmail.com 
    

    and you'll receive:

    250 mx.google.com at your service
    

    From there it is not quite as straightforward as just sending SMTP messages because Gmail has protections in place to ensure you only send emails appearing to be from accounts that actually belong to you. Instead of typing in "Helo", use "Ehlo". I don't know much about SMTP so I cannot explain the difference, and don't have time to research much. Perhaps someone with more knowledge can explain.

    Then, type "auth login" and you will receive the following:

    334 VXNlcm5hbWU6
    

    This is essentially the word "Username" encoded in Base 64. Using a Base 64 encoder such as this one, encode your user name and enter it. Do the same for your password, which is requested next. You should see:

    235 2.7.0 Accepted
    

    And that's it, you're logged in.

    There is one more oddity to overcome if you're using OSx or Linux terminals. Just pressing the "ENTER" key does not apparently result in a CRLF which SMTP needs to end a message. You have to use "CTRL+V+ENTER". So, this should look like the following:

    ^M
    .^M
    250 2.0.0 OK
    

提交回复
热议问题