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

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

问题描述



我只是想在我的Windows上模拟SMTP连接。

我正在编写一个通过有效的GMail用户ID和密码发送邮件的应用程序。 XP的命令行,当我telnet smtp.gmail.com 在465端口 - 我没有看到任何东西。带有标题 Telnet smtp.gmail.com 的空白命令窗口用光标打开。当输入 EHLO 或通常的SMTP握手命令时,提示符会关闭。



我无法弄清楚什么是错误的,哪里。我试图连接到587,它根本不连接在telnet上。任何人都可以澄清,如果我做错了什么?

解决方案

使用Linux或OSx,索林建议,但使用端口465 。 25是通用的SMTP端口,但不是GMail使用的端口。另外,我不相信你想用-starttls smtp

  openssl s_client -connect smtp.gmail.com:465 

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

  220 mx.google.com ... 

输入HELO,您将收到:

  250 mx.google.com为您提供服务

从那里开始并不像发送SMTP邮件那么直截了当,因为Gmail有保护措施来确保您只发送电子邮件似乎来自实际属于你的账户。不要输入Helo,请使用Ehlo。我对SMTP不太了解,所以我无法解释它们之间的差异,也没有时间去研究太多。也许有更多知识的人可以解释。

然后,键入auth login,您将收到以下内容:

  334 VXNlcm5hbWU6 

这实质上是在Base 64中编码的用户名 64编码器,例如这一个,对您的用户名进行编码并输入。请为您的密码做同样的事情,这是接下来要求的。您应该看到:

  235 2.7.0接受

就是这样,你已经登录了。



如果你使用OSx,还有一点需要克服或Linux终端。只需按下ENTER键,显然不会导致SMTP需要结束消息的CRLF。你必须使用CTRL + V + ENTER。所以,这看起来应该如下所示:

  ^ M 
。^ M
250 2.0.0 OK


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 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.

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?

解决方案

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 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

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

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