通过命令行连接到 smtp.gmail.com [英] Connecting to smtp.gmail.com via command line

查看:62
本文介绍了通过命令行连接到 smtp.gmail.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个通过有效的 GMail 用户 ID 和密码发送邮件的应用程序.

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

我只是想在我的 Windows XP 命令行上模拟 SMTP 连接,当我在 465 端口上 telnet smtp.gmail.com 时 - 我什么也没看到.标题为 Telnet smtp.gmail.com 的空白命令窗口将打开并带有光标.当我输入 EHLO 或通常的 SMTP 握手命令时,提示符就会关闭.

I just wanted to simulate the SMTP connection on my Windows XP command line, and when I telnet smtp.gmail.com at 465 port - I don't see any thing. A blank command window with title Telnet smtp.gmail.com opens with cursor. When I type in EHLO or usual SMTP handshake commands, the prompt just closes.

我无法弄清楚哪里出了问题.我尝试连接到 587,它根本无法在 telnet 中连接.如果我做错了什么,谁能澄清一下?

I am unable to figure out whats going wrong and where. I tried connecting to 587, it does not connect in telnet at all. Could anyone please clarify if I am doing something wrong?

推荐答案

使用 Linux 或 OSx,按照 Sorin 的建议进行操作,但改用端口 465.25 是通用 SMTP 端口,但不是 GMail 使用的端口.另外,我不相信你想使用 -starttls smtp

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

您应该获得有关 SSL 会话和响应的大量信息:

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

220 mx.google.com ...

输入

HELO smtp.gmail.com 

您将收到:

250 mx.google.com at your service

从那里开始,它并不像发送 SMTP 邮件那么简单,因为 Gmail 有适当的保护措施,以确保您只发送看似来自实际属于您的帐户的电子邮件.不要输入Helo",而是使用Ehlo".我对 SMTP 了解不多,所以我无法解释其中的区别,也没有时间研究太多.也许有更多知识的人可以解释一下.

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.

然后,输入auth login",您将收到以下信息:

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

334 VXNlcm5hbWU6

这本质上是用 Base 64 编码的单词用户名".使用 Base 64 编码器,例如 这个,对您的用户名进行编码并输入.对您的密码执行相同的操作,这是接下来需要的.你应该看到:

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.

如果您使用的是 OSx 或 Linux 终端,还有一个奇怪的问题需要克服.仅按ENTER"键显然不会导致 SMTP 需要结束消息的 CRLF.您必须使用CTRL+V+ENTER".所以,这应该如下所示:

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

这篇关于通过命令行连接到 smtp.gmail.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆